I'm using a shell script inside codebuild buildspec on Account A to login into Account B and seeing te below error, but when use the commands directly in buildspec file I'm able to login successfully into Account B Error Details
jq: error: Could not open file login.json: No such file or directory
jq: error: Could not open file login.json: No such file or directory
jq: error: Could not open file login.json: No such file or directory
An HTTP Client raised an unhandled exception: Invalid header value b'\r\r\r'
Auth.sh
echo $1
roleArn=$1
aws sts assume-role --role-arn $roleArn --role-session-name testx > login.json
GetAccess=$(jq '.Credentials.AccessKeyId' login.json)
Access=$(echo "$GetAccess" | sed -e 's/^"//' -e 's/"$//')
GetSecret=$(jq '.Credentials.SecretAccessKey' login.json)
secret=$(echo "$GetSecret" | sed -e 's/^"//' -e 's/"$//')
GetTOken=$(jq '.Credentials.SessionToken' login.json)
token=$(echo "$GetTOken" | sed -e 's/^"//' -e 's/"$//')
export AWS_ACCESS_KEY_ID=$Access
export AWS_SECRET_ACCESS_KEY=$secret
export AWS_SESSION_TOKEN=$token
aws s3 ls
buildspec.yam
version: 0.2
phases:
install:
commands:
- ls
build:
commands:
- aws s3 cp s3://mybucket/auth.sh auth.sh
- chmod a+x auth.sh
- ./auth.sh "arn:aws:iam::xxxxx:role/roleToLogin"
- ls
- aws sts assume-role --role-arn "arn:aws:iam::xxxxx:role/roleToLogin" --role-session-name testx > login.json
- GetAccess=$(jq '.Credentials.AccessKeyId' login.json)
- Access=$(echo "$GetAccess" | sed -e 's/^"//' -e 's/"$//')
- GetSecret=$(jq '.Credentials.SecretAccessKey' login.json)
- secret=$(echo "$GetSecret" | sed -e 's/^"//' -e 's/"$//')
- GetTOken=$(jq '.Credentials.SessionToken' login.json)
- token=$(echo "$GetTOken" | sed -e 's/^"//' -e 's/"$//')
- export AWS_ACCESS_KEY_ID=$Access
- export AWS_SECRET_ACCESS_KEY=$secret
- export AWS_SESSION_TOKEN=$token
- rm -f login.json
- aws s3 ls
post_build:
commands:
- echo test
