bash - Env variables not persisting in parent shell -


i have following bash script attempts automate assuming of aws role (i've removed various private settings):

#! /bin/bash # # dependencies: #   brew install jq # # execute: #   source aws-cli-assumerole.sh  unset aws_session_token export aws_access_key_id=<user_access_key> export aws_secret_access_key=<user_secret_key>  temp_role=$(aws sts assume-role \                     --role-arn "arn:aws:iam::<aws_account_number>:role/<role_name>" \                     --role-session-name "<some_session_name>")  export aws_access_key_id=$(echo $temp_role | jq .credentials.accesskeyid) export aws_secret_access_key=$(echo $temp_role | jq .credentials.secretaccesskey) export aws_session_token=$(echo $temp_role | jq .credentials.sessiontoken)  env | grep -i aws_ 

i have execute script using source because otherwise if use standard bash or sh exported environment variables not available within parent shell executing script.

the problem is, when using source doesn't work; , mean: environment variables , correct/updated values showing in parent shell (if execute env | grep aws_ can see correct values).

if try use aws cli tools (e.g. aws s3 ls - list s3 buckets within specific account i've assumed role for) it'll report access key invalid.

but, if manually copy , paste environment variable values , re-export them in parent shell (effectively overwriting them exact same values set), then aws cli command work - not know why. what's different?

jq .blah return output quoted.

so example export aws_access_key_id=$(echo $temp_role | jq .credentials.accesskeyid) result "key" instead need key why xargs works in comment.

if use -r flag raw jq result want export aws_access_key_id=$(echo $temp_role | jq -r .credentials.accesskeyid)


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -