Note: If your issue/bug is regarding the AWS Amplify Console service, please log it in the
Amplify Console GitHub Issue Tracker
Describe the bug
Im using a headless script with default profile to run the init command in Jenkins with codebuild plugin, but I get the error:
[AWS CodeBuild Plugin] init failed
[AWS CodeBuild Plugin] Error: AWS access credentials can not be found.
I use the headless script from https://github.com/aws-amplify/amplify-cli/blob/multienv/packages/amplify-cli/sample-headless-scripts/headless_init_new_project.sh
with angular framework.
amplify version: @aws-amplify/[email protected]
node version: v8.11.0
npm version: 6.10.3
I've read that I need to set to default profile in a EC2 instance with the last version of amplify but still get an error.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Init the amplify project.
Additional context
This is my headless_init.sh script:
```
set -e
IFS='|'
ANGULARCONFIG="{\
\"SourceDir\":\"src\",\
\"DistributionDir\":\"dist/kushki-spa-snr\",\
\"BuildCommand\":\"npm run-script build\",\
\"StartCommand\":\"npm run-script start\"\
}"
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\"\
}"
AMPLIFY="{\
\"projectName\":\"kushki-spa-snr\",\
\"envName\":\"dev\",\
\"defaultEditor\":\"idea14ce\"\
}"
FRONTEND="{\
\"frontend\":\"javascript\",\
\"framework\":\"angular\",\
\"config\":$ANGULARCONFIG\
}"
PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"
amplify init \
--amplify $AMPLIFY \
--frontend $FRONTEND \
--providers $PROVIDERS \
--yes
```
Can you make sure that you have your AWS Config and Creds set in ~/.aws/config
and ~/.aws/credentials
files in your EC2 instance?
I already create a profile in the EC2 instances but when I run cat ~/.aws/config in codebuild there is no profile set. Is there a way to use the headless script with the acces key and secret key instead of using a profile? I can set those keys in the environment.
Hey @moransk8,
You could try installing and using the aws cli to create the default profile from your access key id and secret
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
aws configure set default.region $AWS_REGION
Make sure to set the env variables AWS_ACCESS_KEY_ID, secret and region before you run the commands above or replace them with the real values.
@moransk8
Yes you can use credential keys directly instead of using a profile.
Use this script as the reference
https://github.com/aws-amplify/amplify-cli/blob/master/packages/amplify-cli/sample-headless-scripts/headless_configure_project.sh
and in AWSCLOUDFORMATIONCONFIG change "userProfile" to false, and set the keyId and accessKey.
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":false,\
\"profileName\":\"default\",\
\"accessKeyId\":\"headlessaccesskeyid\",\
\"secretAccessKey\":\"headlesssecrectaccesskey\",\
\"region\":\"us-east-1\"\
}"
@rakannimer
We don't guarantee that the aws CLI credentials setup will be automatically picked up by the Amplify CLI.
specially if there's temp credentials and caching
thanks @rakannimer this solve the issue.
Most helpful comment
Hey @moransk8,
You could try installing and using the aws cli to create the default profile from your access key id and secret
Make sure to set the env variables AWS_ACCESS_KEY_ID, secret and region before you run the commands above or replace them with the real values.