Get AWS EC2 tags to environment parameters for apache2

Objective:

  • AWS instances are assigned tags per instance.
  • Need tags to be environment parameters for Apache2; thus, web application can retrieve environment parameter.

 

Step 1: Configure tags in AWS EC2 instance

 

aws_ec2_tag

Step 2: Setup IAM user and get access key id and secret access key

 

Step 3: Access to SSH and append following shell scripts

Append following script to /etc/apache2/envvars

  • Note that you need to replace AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_DEFAULT_REGION
  • Note that you need  to update allowed_tag variable if you want to add different tag name rather than ENVIRONMENT

 

Step 4: Restart Apache2

 

Step 5: Check environment parameters