Unable to update environment properties in AML 2 (rails)

0

In AML1 we could easily modify the file(/opt/elasticbeanstalk/deploy/configuration/containerconfiguration) and store variables from SSM(system manager) in the former file and the beanstalk automatically updates the environment properties.but in AML2 this feature is removed and the file doesnt exist.Also we tried getting data from SSM and running export command but still properties dont change.so how do we change environment properties from SSM parameters in this case?

1 Answer
0

Hi there,

I understand that you are unable to update environment properties in Amazon Linux 2.

I would like to inform that in Amazon Linux 2 uses “get-config“ command tool is used to retrieve environment variable values and other platform and instance information. Please refer documentation for more information [1]. The tool is available at ”/opt/elasticbeanstalk/bin/get-config“ and currently “/opt/elasticbeanstalk/deploy/configuration/containerconfiguration” is not supported anymore.

Also, SSM parameter store not directly supported by the beanstalk and needs to integrated using ebextension or .platform script based on the use-case, to fetch the parameters from the SSM you can use dynamic referencing approach as explained below: (I have tested below approach in my test environment and its working as expected.)

Step 1: Created a “test” variables in parameter store from the console[2] with type as string.


Step 2: Created below ebextension which reads value from the parameter store and add them to ElasticBeanstalk environment variable. Please note my ec2-instance role has "AmazonSSMFullAccess" access for testing. You can use the minimal permission as per your requirement.

testssm.config


=====================================================================================
option_settings:
   aws:elasticbeanstalk:application:environment:

        MY_ENV_VAR: ‘{{resolve:ssm:test:1}}' <--  syntax to extract test value from the SSM parameter store.
=====================================================================================

After deploying the above ebextension I could observe in your Beanstalk console, that the value of the "MY_ENV_VAR" environment variable is "{{resolve:ssm:Test:1}}", however it will be resolved the expected SSM parameter value inside the environment/application. Here is the output of checking my environment variables from inside my instance: (doing SSH into instance)

=================================================
/opt/elasticbeanstalk/bin/get-config environment
=================================================

Output: {"BUNDLER_DEPLOYMENT_MODE":"true","BUNDLE_WITHOUT":"test:development","MY_ENV_VAR":"Akash"

I could observe that MY_ENV_VAR correctly resolved to "Akash".

Step 3: Create the ebextension mentioned in [3] if you like to export the value to shell.

======================================================================================
commands:
setvars:
command: /opt/elasticbeanstalk/bin/get-config environment | jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' >
/etc/profile.d/sh.local.
packages:
jq: []
======================================================================================

Before Output:

=================================================
 [root@ip-172-31-1-52 ~]# env | grep MY_ENV_VAR
 [root@ip-172-31-1-52~]# 
=================================================

After Output

=================================================
  [root@ip-172-31-1-54 ~]# env | grep MY_ENV_VAR
  MY_ENV_VAR=Amazon
=================================================

Also I would like to mention here that if you want to fetch multiple SSM parameters, you can use AWS CLI approach to call get-parameters-by-path[4] using .platform/hooks, this will help you fetch the values based on configured path. Attaching one third party article explains how to fetch multiple SSM parameters using AWS CLI. [5]

Kindly test the feasibility at your end.

I hope this helps you

Thanks.


References:


  1. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platforms-scripts.html#custom-platforms-scripts.get-config.commands
  2. https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-create-console.html
  3. https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-env-variables-shell/
  4. https://docs.aws.amazon.com/cli/latest/reference/ssm/get-parameters-by-path.html
  5. https://www.workfall.com/learning/blog/how-to-use-aws-ssm-parameter-store-in-aws-elastic-beanstalk-instances/
AWS
Akash_P
answered a year ago
  • Thank you for answering.but there are some issues:- according to your first approch (storing in testssm.config
).we cant do that beacuse we dont want to hardcode the properties in the config file(as we use three environments with same project and the SSM parameters are not tied to the environment but stored in a path(like for testing /app/testing/ and for production /app/production/).

  • Also i have tried storing the SSM parameters in the /etc/profile.d/sh.local by ssm get parameters by path command ,but still it doesnt update the environment properties and the rails application doesnt detect those variables while deploying and the deployement fails.but those variables are available correctly when i type env command on the AWS SSH.(Not able to understand why this happening). If possible can you provide other ways to update the properties(please note i want to update environment properties not environment variables as updating environment variables doesnt seem to work).

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions