How do we configure an Elastic Bamboo Image to auto-associate IP address?
Asked by Sergey Morkovkin:

Hello.

Just trying to auto-associate an IP to an elastic instance. What was done:

1. Configured to upload AWS private key and certificate to new instance.

2. In the startup script run the following command: ec2-associate-address -K /root/pk.pem -C /root/cert.pem -i $(curl -s <http://169.254.169.254/latest/meta-data/instance-id>) xx.xxx.xx.xxx

What's interesting is that this command works well from the terminal, but doesn't work on startup. I've also tried to invoke it from rc.local. Still no effect. Could you please suggest a workaround?


Answers:
author: LucasA
body: Hello,

Put this script to run on bin/customise-extras.sh (<https://confluence.atlassian.com/display/BAMBOO/Configuring+elastic+instances+to+use+the+EBS>). This script runs after the system starts with root privileges.

Cheers,

Lucas Luma

Atlassian Support


author: Matthew Sullivan
body: I know this is a bit old but it has become easier to do now, and without EBS. AWS added the IAM User concept and priveleges, so you can configure a new user with just permissions to set the IP address.

Go to the Security Credentials and create a new user, download and keep the credentials. Attach a custom Security Policy with the following, which will restrict the permissions to associate the IP Address

```
{  "Statement": [    {      "Action": [        "ec2:AssociateAddress",        "ec2:DisassociateAddress"      ],      "Effect": "Allow",      "Resource": "*"    }  ]}
```

<br />

Then in Bamboo, edit the image to add this startup script:

```
export EC2_HOME=/opt/aws/apitools/ec2export JAVA_HOME=/opt/jdk-6/opt/aws/bin/ec2-associate-address -O [aws-access-key] -W [aws-secret-key] -i $(/usr/bin/curl -s http://169.254.169.254/latest/meta-data/instance-id) [eip]sleep 30
```

Replacing the \[aws-access-key\] and \[aws-secret-key\] with that of the IAM user key, and the \[eip\] to be the Elastic IP. $(/usr/bin/curl -s <http://169.254.169.254/latest/meta-data/instance-id>) curls the AWS metadata and gets the latest instance ID. I had connection reset issues pretty consistently, and adding a the sleep 30 seemed to resolve this.


author: Matthew Sullivan
body: I know this is a bit old but it has become easier to do now, and without EBS. AWS added the IAM User concept and priveleges, so you can configure a new user with just permissions to set the IP address.

Go to the Security Credentials and create a new user, download and keep the credentials. Attach a custom Security Policy with the following, which will restrict the permissions to associate the IP Address

```
{  "Statement": [    {      "Action": [        "ec2:AssociateAddress",        "ec2:DisassociateAddress"      ],      "Effect": "Allow",      "Resource": "*"    }  ]}
```

<br />

Then in Bamboo, edit the image to add this startup script:

export EC2_HOME=/opt/aws/apitools/ec2  
export JAVA_HOME=/opt/jdk-6  
/opt/aws/bin/ec2-associate-address -O \[aws-access-key\] -W \[aws-secret-key\] -i $(/usr/bin/curl -s <http://169.254.169.254/latest/meta-data/instance-id>) \[eip\]  
sleep 30

Replacing the \[aws-access-key\] and \[aws-secret-key\] with that of the IAM user key, and the \[eip\] to be the Elastic IP. $(/usr/bin/curl -s <http://169.254.169.254/latest/meta-data/instance-id>) curls the AWS metadata and gets the latest instance ID. I had connection reset issues pretty consistently, and adding a the sleep 30 seemed to resolve this.


Tags: assign

automation

ip-address