Resources: MyEC2Instance: Type:AWS::EC2::Instance DeletionPolicy:Retain# here Properties: ImageId:ami-a4c7edb2 InstanceType:t2.micro MyEBSVolume: Type:AWS::EC2::Volume DeletionPolicy:Snapshot# here Properties: Size:1 VolumeType:gp2
Termination protection
Enable termination protection to protect the stack to be deleted
Referent parameters from SSM parameter store
You can also use the public parameters from SMM Parameter Store such as AMI IDs
1 2 3 4 5 6 7
Parameters: InstanceType: Type:AWS::SSM::Parameter::Value<String># here Default:/EC2/InstanceType ImageId: Type:AWS::SSM::Parameter::Value<AWS::EC2::Image::Id># here Default:/EC2/ImageId
DependsOn
Define resources creation orders
1 2 3 4 5 6 7 8 9 10
Resources: MyEC2Instance:# created after MyRDSInstance Type:AWS::EC2::Instance Properties: ... DependsOn:MyRDSInstance MyRDSInstance:# created first Type:AWS::RDS::DBInstance Properties: ...
eb create “eb-env”: upload zip file into S3 & create a new environment
eb open: access the environment (open the home page in your browser if the environment is Web application)
eb status
eb health [–refresh]
eb logs
eb deploy
eb terminate
Saved Configurations
Elastic Beanstalk native IaaC
eb config commands (can be done through console as well)
A good way to recreate the environment into another region
1 2 3 4 5 6
# Create a saved configuration from the current environment configuration eb config save "eb-env" --cfg "cfg-name" # Upload current local configuration file to Saved Configurations eb config put "cfg-name" # Use saved configuration to update environment eb config "eb-env" --cfg "cfg-name"
# Before the web server has been set up & before the application code has been unpacked commands: run_commands: command:echo"this is a command" cwd:/home/ec2-user # Before the application has finished its deployment container_commands: run_container_commands: command:echo"this is a container command" run_container_commands_once: command:echo"this container command is executed only once" leader_only:true
Application version lifecycle
Default max number of application versions is 1000
You can set lifecycle to delete older versions automatically
by total count
by age
You can retain or delete the bundle in S3
You need provide a service role to perform the actions
Managed Updates
Define a update window, patches will be automatically to the instances
Deployment Strategies
All at once
Rolling
Rolling with additional batches
Immutable
Blue/green (not Elastic Beanstalk native)
Use Route 53 / Swap URL feature
Worker Environment
Pool messages from SQS
Use cron.yaml file to run scheduled works
Multi-container Docker
Use ECS
Define containers in Dockerrun.aws.json file
Lambda
Secrets
Encrypted environment variables (using KMS)
SMM Parameter Store secret string
Secrets Manager
SAM
1 2 3 4 5 6 7 8 9 10 11
# Create SAM project locally sam init --runtime python3.8 # Resolve dependencies and copy sources into .aws-sam directory sam build # Test function and api locally sam local invoke myFunction -e events/event.json sam local start-api # Package files and upload to S3 bucket sam package --output-template my-template.yaml --s3-bucket my-s3-bucket # Deploy sam deploy --template-file my-template.yaml --stack-name my-sam-stack --capabilities CAPABILITY_IAM