I have a bash script that assumes an IAM role and then pass the credentials to the next command:
#!/bin/bash
sudo su <<EOF
aws sts assume-role --role-arn "arn:aws:iam::0123456789:role/SomeRole" --role-session-name AWSCLI-Session > /awsCredential
awscurl https://someApi --request POST --region us-west-2 --access_key $(cat /awsCredential | jq -r '.Credentials.AccessKeyId')
EOF
When running the script, $(cat /awsCredential | jq -r '.Credentials.AccessKeyId')
resolved to empty, but if I run the above commands manually from terminal, I can see it resolves to the AWS ACCESS KEY ID returned from the assume role command, does anyone know why is that?