Part 6. AWS at a glance - Elastic Beanstalk, CloudFormation

· Tech· Cloud
CloudCertification

AWS Elastic Beanstalk

Elastic Beanstalk is a service for deploying and orchestrating web applications and services. The deployment environment for almost all apps is often similar. Therefore, if you have multiple apps to manage but need to have a similar infrastructure structure, you can conveniently deploy them using Elastic Beanstalk through basic Preset or Custom Configure settings.

  • Elastic Beanstalk provides free services, but the services used incur costs.
  • Composed of Application, Application Version, Environment (Worker, Web-Server)
  • Provides various languages
  • When you set up Elastic Beanstalk, you can check events created in CloudFormation.

Rolling updates and deployments

  • AllAtOnce - Deployment to all instances at once, the fastest method but impossible to deploy without interruption
  • Rolling - Standard rolling distribution method
  • RollingWithAdditionalBatch- Before starting deployment, maintain full capacity by placing additional instances.
  • Immutable - perform immutable updates for all deployments
  • TrafficSplitting- Perform traffic splitting deployment to Canary test the application deployment elastic-beanstalk-deploy-options

Lifecycle Policy

You can save 1000 application versions, and to create another version in the future, you must delete the previous version. You can decide how to manage previous versions through Lifecycle Policy.

  • limit by total count
  • limit by age

Extensions

In ./ebextensions/, you can add the settings required for Elastic Beanstalk as a YAML/JSON format file. For example, environment variable injection is possible depending on .config settings. Alternatively, you can set the load balancer type as shown in the example below.

option_settings:
aws:elasticbeanstalk:environment:
LoadBalancerType: network

Migration

After setting up the Elastic Beanstalk environment, you cannot change the load balancer. If you want to change it, you must deploy the application to a new environment through migration. After that, you can connect through CNAME Swap or Route53 update processing.

CloudFormation

This is a service that allows you to check things such as infrastructure management, replication, and events. Work with templates and stacks. The template is a text file in a format such as json or yaml, and the following example is provided by AWS. The json file below provisions an EC2 instance of type t2.micro.

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "A sample template",
"Resources": {
"MyEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-0ff8a91507f77f867",
"InstanceType": "t2.micro",
"KeyName": "testkey",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/sdm",
"Ebs": {
"VolumeType": "io1",
"Iops": 200,
"DeleteOnTermination": false,
"VolumeSize": 20
}
}
]
}
}
}
}

Advantages of using CloudFormation

  • Git has the advantage of being able to manage code for infrastructure structures.
  • You can easily check where costs arise and make predictions.
  • By having separate VPC, Network, and App stacks, you can manage multiple apps and layers through separation of concerns.

How CloudFormation works

When you upload a template to S3, CloudFormation creates a stack based on this content. And we will create a resource in AWS. When you delete a stack, the resources created along with it also disappear.

  • How to create a template There are several ways, including using Infrastructure Composer or Designer and creating the template directly.

CloudFormation Settings

Resources

It is a key element that makes up the template and is expressed as service-privider::service-name::data-type-name. (ex. AWS::EC2::Instance) Not all resources are supported.

Parameters

For example, when creating an instance, you can specify which instance to select by setting the value AllowedValues. When placing a reference as a parameter value, you can indicate the reference by putting an expression such as !Ref in front of it. If the template has a Pseudo parameter value, it will have that value as the default.

Parameters:
ParameterLogicalID:
Description: Information about the parameter
Type: DataType
Default: value
AllowedValues:
- value1
- value2

Mappings

You can specify mapping values in advance and use them like variables for reference. Unlike parameters, it is convenient when values ​​are used in multiple places.

AWSTemplateFormatVersion: 2010-09-09
Mappings:
AMIIDMap:
us-east-1:
MyAMI1: ami-0ff8a91507f77f867
MyAMI2: ami-0a584ac55a7631c0c
us-west-1:
MyAMI1: ami-0bdb828fd58c52235
MyAMI2: ami-066ee5fd4a9ef77f1
Resources:
myEC2Instance:
Type: "AWS::EC2::Instance"
Properties:
ImageId: !FindInMap [AMIIDMap, !Ref "AWS::Region", MyAMI1]
InstanceType: t2.micro

Outputs&Exports

Declare output values from the stack. It can also be used to reference other stack values.

Outputs:
OutputLogicalID:
Description: Information about the value
Value: Value to return
Export:
Name: Name of resource to export

####Conditions As shown in the yaml below, you can add a condition to create EC2 in the CreateProdResources condition for creating an operating server.

Resources:
MountPoint:
Type: "AWS::EC2::Instance"
Condition: CreateProdResources

Intrinsic Functions

  • !Ref - When a reference is needed
  • !GetAtt - When you need to get the value of a specific resource
  • !FindInMap - When searching for specific content in a Mapping value
  • !ImportValue - When importing a value from another stack
  • !Base64 - When Base64 encryption is required

Rollbacks

Rollback can be used to respond to failure when creating or updating a stack. You can choose to revert everything or just the failed stack.

Service Role

Service Role is granted to perform tasks such as creating or updating resources in the stack. To use this feature, the user must have iam:PassRole permission. ####Capabilities If your template requires you to set up IAM, you will need to consent to the creation of IAM resources in Capabilities.

  • CAPABILITY_IAM
  • CAPABILITY_NAMED_IAM

Policy

Deletion Policy
  • Delete - Used to delete templates or remove resources. Default.
  • Retain - This is a setting that preserves resources even when CloudFormation deletes them.
  • Snapshot - Setting to take a snapshot of a resource before deletion.
Stack Policy

This refers to allowing the stack to decide whether or not to process an Action through resource-specific settings. If you look at the json below, you can see that updates are blocked for LogicalResourceId/ProductionDatabase.

{
"Statement" : [
{
"Effect" : "Allow",
"Action" : "Update:*",
"Principal": "*",
"Resource" : "*"
},
{
"Effect" : "Deny",
"Action" : "Update:*",
"Principal": "*",
"Resource" : "LogicalResourceId/ProductionDatabase"
}
]
}

Termination Protection

To prevent accidental deletion of the stack, you must change Termination Protection to inactive when deleting to enable deletion.

Custom Resources

For example, when clearing the stack, if there is an Object in S3, the resource will not be deleted. Therefore, in this case, you can use Custom Resources to empty the bucket with Lambda and ensure that stack deletion is executed correctly. ####StackSets When you want to create the same stack in multiple regions, you can create StackSets and create a stack in the target.

Comments

No comments yet. Be the first!

    164 posts in 테크

    15 / 164