Best Practices
Web server A approach:
- Launch with user data script
- Run additional commands manually
- Update user data script to retain configuration record
- Can copy user data to new instances with same configurations
When you launch an EC2 instance, you can specify user data to run an initialization script (shell script or cloud-init directive):
/var/log/cloud-init-output.log
C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log
Instance metadata is information about your instance accessible from the instance at:
URL http://169.254.169.254/latest/meta-data/
Metadata | Value |
---|---|
instance-id | i-1234567890abcdef0 |
mac | 00-1B-63-84-45-E6 |
public-hostname | ec2-203-0-113-25.compute-1.amazonaws.com |
public-ipv4 | 67.202.51.223 |
local-ipv4 | 10.251.50.12 |
#!/bin/bashyum update -y
#!/bin/bashyum update -yyum install httpdservice httpd startchkconfig httpd on
sudo rm /var/lib/cloud/instances/*/sem/config_scripts_user
/var/lib/cloud/instance/scripts/part-001
Critical If you skip step 3, your modified user data script won’t run.
Best Practices
Web server A approach:
Not Best Practices
Web server B approach:
Base AMIs:
Used as base AMI from which to create silver or golden AMIs
AWS Managed Services (AMS) provided mutable AMIs:
Customized immutable AMIs:
The model you choose impacts how these configurations are provisioned:
Placement groups give you control of where a group of interdependent instances run in an Availability Zone:
Cluster
Packs instances close together inside an Availability Zone
Benefits: Helps workloads achieve low-latency network performance
Partition
Spreads instances across logical partitions
Benefits: Groups of instances in one partition do not share underlying hardware with groups in different partitions
Spread
Strictly places small group of instances across distinct underlying hardware
Benefits: Reduces correlated failures
User data lets you configure an EC2 instance when you launch it. Information about a running instance can be accessed through an instance metadata URL. There are three main AMI deployment models: Basic AMIs, Silver AMIs and Golden AMIs. Placement groups give you control of where a group of interdependent instances run in an Availability Zone.