0
votes

I wrote a cloud formation template to create an Auto Scaling group with size as 1. Now I want to assign an elastic IP to this instance via cloud formation.

Unfortunately, AWS::AutoScaling::AutoScalingGroup doesn't have any Fn::GetAtt to get the instance-id attached to this auto scaling group.

Is there any other way to get the instance-id for this instance? Or can we directly get instance-id of an existing EC2 instance from its Name tag in cloud formation?

Userdata script is not acceptable, as it requires AWS IAM credentials.

1
This answer talks about userdata script which is not acceptable, as it requires AWS IAM credentials. We don't expect template users to setup IAM credentials, before using it.Rakesh Ranjan
You don't need IAM credentials for applications running on EC2, you can use IAM roles.strongjz

1 Answers

0
votes

Change the cloudformation to create an instance, assign an EIP and then associated the instance with the ASG. All of this possible in cloudformation.

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html

InstanceId

The ID of the Amazon EC2 instance you want to use to create the Auto Scaling group. Use this property if you want to create an Auto Scaling group that uses an existing Amazon EC2 instance instead of a launch configuration.

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html#cfn-as-group-instanceid

Edit: This EIP will be lost if the instance scales, A way to guarantee that the EIP stays with the instance is with an userdata script that attaches and an IAM role that has permissions to do so.