Home > Net >  Why variables that I export in bash script does not work on EC2?
Why variables that I export in bash script does not work on EC2?

Time:04-27

When I create EC2 inst. I use bash script into user data where I export variable AWS credentials and then run the command to copy files from S3 bucket. But this command is not executed.

#! /bin/bash 
export AWS_ACCESS_KEY_ID=MYACCESSKEY
export AWS_SECRET_ACCESS_KEY=MYSECRETKEY
aws s3 cp s3://mys3bucket/ ./

How to fix it?

CodePudding user response:

It is run on its own bash process which dies at the end of your script.

Exported variables are preserved only for the lifetime of your script and they are also visible from child processes of your script.

  • Related