How to Launch EC2 Auto Scaling with an IAM on AWS Cloud

 

AutoscalingAWS Auto Scaling allows the user to automatically scale the Amazon EC2 compute resources up or down as per the defined conditions. The AWS resources launched with Auto Scaling require the AWS security credentials to access other AWS resources. AWS provides the IAM Role to easily access the other AWS resources from the newly launched EC2 computer resources.

(For example, a newly launched EC2 instance may need the AWS credentials to take a regular backup of the EBS volume).

To assign the IAM Role to Auto Scaling, the user has to create an IAM instance profile with EC2 access. An instance profile is a container for the IAM Role. The user has to first create an IAM role, which has the permission to access the EC2 resources. The above mentioned role must be added to the instance profile.

The present guide demonstrates how to launch Auto Scaling with an IAM role. Since AWS does not provide the management console for Auto Scaling, all the tasks would be performed by CLI.

 

If the user has created an IAM role with the AWS management console, there is no requirement to create a separate instance profile. This is because the AWS console automatically creates an instance profile and the role is assigned to it. However, if the instance profile is created with the AWS console, the name should be the same as the IAM role. The user can get the ARN (Amazon Resource Name) of the instance profile from the AWS console.

If the user creates a role with AWS CLI, the instance profile has to be created separately with the following command:

“iam-instanceprofilecreate”

1. Create an IAM role, which has full access to the AWS EC2 resources. Note down the ARN of the profile or the name of the role.

 

 

2. Download and install the Auto Scaling CLI.

3. Create a new launch configuration. The user has to provide the iam-instance-profile with the IAM Role as one of the parameters.

The user can specify the security group and the key-pair name in the launch configuration with the below mentioned command:

as-create-launch-config <Config Name> --image-id <Image ID> --region <Region> --instance-type <Instance Type> --key <Key-Pair Name> --group <Security Group Name> --iam-instance-profile <Role Name from step#1>

 

 

4. Create a new Auto Scaling group.

Run the following command:

as-create-auto-scaling-group <Group Name> --launch-configuration <Launch Config Name> --region <Region Name> --availability-zones <Availability Zone> --min-size <Min Size> --max-size <max Size>

 

 

5. Verify the instances launched with Auto Scaling and the Auto Scaling group details with the following command:

as-describe-auto-scaling-groups <Group Name> --region us-west-2 –headers

 

 

6. Auto Scaling has now launched two instances as per the minimum size or the desired capacity. Both the instances are launched with the IAM Role. Check the instance details from the AWS Console, which will display the role name.

 

 

7. The above mentioned command helps the user to launch instances as a part of Auto Scaling with an IAM role. This ensures that the instance launched with Auto Scaling will have access to the EC2 resources based on the IAM role access policy.

Advertisements
Leave a comment

Leave your opinion

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: