Prabin Deka
Prabin Deka

Reputation: 301

Tag AWS beanstalk deployment using .config file in .ebextensions

I added a scripts.config file to .ebextensions at the root of my Node app deployed in beanstalk.I did not see the tags for the EC2 instances in the console. Nor did I see any mention of 1_add_tags in beanstalk logs. What did I do wrong and how do I find out if the commands in the script.config were called at all!

The config file in .ebextensions is as follows ....

01_add_tags:

command: ec2-create-tags $(ec2-metadata -i | cut -d ' ' -f2) --tag Environment=Production --tag Name=Proxy-Server --tag Application=something

env:

EC2_HOME: /opt/aws/apitools/ec2
EC2_URL: https://ec2.ap-southeast-2.ama...
JAVA_HOME: /usr/lib/jvm/jre
PATH: /bin:/usr/bin:/opt/aws/bin/

Cheers,

Prabin

Upvotes: 1

Views: 2558

Answers (2)

Prabin Deka
Prabin Deka

Reputation: 301

Amazon's answer to the problem. (This worked for me) ...

You can utilise the ebextensions to execute certain commands on instance boot. Supposing that you want to implement this on Linux based containers. I have formulated a sample config file for you and attached to this case.

Please follow below guidelines :

  1. In the AWS Management console, check the IAM Role/Instance profile used by beanstalk. By default it uses "aws-elasticbeanstalk-ec2-role". Add permissions for this role to create new tags (ec2:CreateTags).
  2. If you do not have ".ebextensions" folder at the root of your application or the "WEB-INF" folder, then create the folder.
  3. Modify the key value pairs in the config file. Multiple pairs are separated by a space.

A sample snippet is as below:

   {
        "container_commands": {
            "01_add_tags": {
                "command": "aws ec2 create-tags --resources $(GET http://169.254.169.254/latest/meta-data/instance-id) --tags Key=ClientName,Value=testClient Key=NewTag,Value=new-value --region us-east-1"
            }
        }
    }
  1. Add the modified config file in the ".ebextensions" folder.
  2. Upload this version to beanstalk. It should launch new instances and execute the config file.
  3. Please give it sometime, preferably till the instances pass EC2 instance status checks. Refresh the page for the additional tags to be displayed.

Please note that we are using "Container_commands" instead of "Command" used in the blog. Container Commands run after the application and web server have been set up and the application version file has been extracted, but before the application version is deployed. This is important as these commands have access to environment variables such as your AWS security credentials set by the instance-profile.

I would recommend you to go through the restrictions for AWS Resources tagging mentioned at http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-restrictions I would like to highlight that maximum number of tags per resource is 10.

Also check the table for tagging support for certain resource. For example, currently tagging is not supported for ELB.

Upvotes: 6

Marcus Lind
Marcus Lind

Reputation: 11470

I had the similar problem where I tried to install libjpeg using the ./ebextensions/foo.config file. I tried everything but was never able to find a good solution.

I was able to solve it though, by setting up a completely new Elastic Beanstalk Application and then deploying my same version on the new instance instead. When I did this everything was installed perfectly and working fine.

Check out my answers here:

Hope this fixes your issues as well.

Upvotes: 0

Related Questions