New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/opt/elasticbeanstalk/bin/get-config doesn't exist for Amazon Linux 2 Platforms #111
Comments
@curtismorte This is great stuff! Thanks for posting. It would be wonderful if you could post your solution on the AWS Beanstalk forum! |
Eh? Why is this closed if AWS know a ton of their own scripts don't work on their own new platform. Maybe I can knock up a compatability script and ship that as a .ebextension file... |
@tomchiverton Thanks for asking. As I wrote above, I closed the issue because we're aware of it and we're tracking it internally, so we didn't need to keep the GitHub issue open. In this specific case, the team indicated to me their intention of bringing back get-config (or a version of it) to the new AL2 platforms. That said, an .ebextensions file that people can use for now would definitely be welcome. I apologize that we're behind on providing up-to-date examples for the AL2 platforms. |
My .ebextensions file. I've started from @curtismorte's solution. Features:
# Filename: .ebextensions/000-get-config.config
files:
"/opt/elasticbeanstalk/bin/get-config-json":
mode: "000755"
content: |
#!/usr/bin/env bash
# -----------------------------------------------------
# Get all environment variables as JSON key value pairs
# -----------------------------------------------------
# https://github.com/awsdocs/elastic-beanstalk-samples/issues/111#issue-614915898
# Get the Region
ENV_REGION="$(</opt/elasticbeanstalk/config/ebenvinfo/region)"
# Get the Stack ID
ENV_STACK_ID="$(</opt/elasticbeanstalk/config/ebenvinfo/stackid)"
# Pass the variables to the CloudFormation Meta Data command.
# Pipe the data to JQ to reduce the environment variables array to an actual key value map
echo "$(sudo /opt/aws/bin/cfn-get-metadata -s ${ENV_STACK_ID} -r AWSEBBeanstalkMetadata --region ${ENV_REGION} -k "AWS::ElasticBeanstalk::Ext.Parameters.EnvironmentVariables" | jq -c '. |= reduce (.[] | split("=")) as [$key, $value] ({}; .[$key] = $value)')"
"/opt/elasticbeanstalk/bin/export-config":
mode: "000755"
content: |
#!/usr/bin/env bash
# Run: `export $(sudo ./export-config)`
# https://stackoverflow.com/questions/48512914/exporting-json-to-environment-variables
echo $(./get-config-json | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]")
"/opt/elasticbeanstalk/bin/get-config":
mode: "000755"
content: |
#!/usr/bin/env bash
# Run: `sudo ./get-config DATABASE_URL`
echo $(./get-config-json | jq -r ".$1")
|
coudn't this be merged in? not a good idea? |
@lorenzoLectrefy I'm open to merging a PR with code like the above, if anyone submitted it into the configuration-files/community-provided directory. I'd ask that the script name would not be Folks who want to use the temporary solution can explicitly change their calls to use the temporary name. |
@lorenzoLectrefy Actually never mind. We already have one: In hindsight, it should have been called something other than |
@dankhen, I believe I tried that script before and it didn't work. I'm afraid I can't remember what exactly failed. |
@MatthiasKunnen In that case, you're welcome to both submit yours as well, and correspond with the other example's submitter to point out issues. |
@dankhen any idea on timescale for release of fix? |
@lorenzoLectrefy Unfortunately we cannot share a specific time. An engineer is working on implementing it, and we'll release it in one of the coming AL2 platform updates. |
There are also scripts that use it with the container argument e.g.
Will this be added as well? |
@DangerDawson Yes, we'll implement the complete set of get-config commands, to be consistent with the Amazon Linux AMI (AL1) version of the tool. |
$ sudo ENV_REGION="$(</opt/elasticbeanstalk/config/ebenvinfo/region)"
-bash: /opt/elasticbeanstalk/config/ebenvinfo/region: Permission denied I got the above error. |
Later AL2 based Beanstalk's do have the official version, simply remove this script and upgrade. |
Any update on this? None of the proposed solutions have worked for me. |
@culov No workaround is necessary anymore. We brought back |
Issue:
In a lot of
.ebextensions
configurations for Amazon Linux 1.X.X platforms, you can get environment configurations using the following command within bash files:TL;DR
The file
/opt/elasticbeanstalk/bin/get-config environment
is missing from Amazon Linux 2. To reproduce some functionality like so, we can use the output from calling/opt/aws/bin/cfn-get-metadata
.Possible Solution:
After some inspection in the logs, I was able to deduce that you can still access environment variables, but from using a different command:
/opt/aws/bin/cfn-get-metadata
I was able to get environment variables in the following way:
/opt/aws/bin/cfn-get-metadata
to get environment variablesConclusion
I feel like this isn't an optimal solution, but was able to give me what I needed relative to what I was able to find though my own inspection.
Closing Thoughts
I have some final thoughts for other people that may help to elaborate more on what the optimal solution for this could be:
/opt/elasticbeanstalk/config/ebenvinfo/env
is temporarily written during the build process. Exposing or extending the same script that builds this file may produce the missing functionality from Amazon Linux v1's/opt/elasticbeanstalk/bin/get-config
..platform/hooks/prebuild
) and take the output fromENV_VARS_KWARGS
and write it to a file. You could access the file like so:The text was updated successfully, but these errors were encountered: