I'm deploying the front-end of my website to amazon s3 via Gitlab pipelines. My previous deployments have worked successfully but the most recent deployments do not. Here's the error:
Completed 12.3 MiB/20.2 MiB (0 Bytes/s) with 1 file(s) remaining
upload failed: dist/vendor.bundle.js.map to s3://<my-s3-bucket-name>/vendor.bundle.js.map Unable to locate credentials
Under my secret variables I have defined four. They are S3 credential variables (AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY)
for two different buckets. One pair is for the testing branch and the other is for the production branch.
Not - the production environment variables are protected and the other variables are not. Here's the deploy script that I run:
#/bin/bash
#upload files
aws s3 cp ./dist s3://my-url-$1 --recursive --acl public-read
So why am I getting this credential location error? Surely it should just pick up the environment variables automatically (the unprotected ones) and deploy them. Do I need to define the variables in the job and refer to them?
To resolve this issue, make sure that your AWS credentials are correctly configured in the AWS CLI. Note: If you still receive an error when running an AWS CLI command, make sure that you're using the most recent AWS CLI version.
To access and manage your security credentials, sign into your AWS console as an IAM user, then navigate to your user name in the upper right section of the navigation bar. From the drop-down menu, select My Security Credentials, as shown in Figure 1.
An "Unable to locate credentials" error indicates that Amazon S3 can't find the credentials to authenticate AWS API calls. To resolve this issue, make sure that your AWS credentials are correctly configured in the AWS CLI.
Setting up GitLab CI. We need to inject the credentials in the GitLab runner. Go to your project, Settings -> CI / CD -> Secret variables and set two variables: AWS_ACCESS_KEY_ID with the new user’s access key. AWS_SECRET_ACCESS_KEY with the new user’s access secret key.
Of course, standard S3 prices will apply. We will use GitLab CI, since it is shipped with GitLab and deeply integrated with it. Gitlab CI is a very powerful system of Continuous Integration, with a lot of different features, and with every new releases, new features land. It has a rich technical documentation that I suggest you reading.
This means that if you have credentials configured incorrectly on a credential provider with higher precedence, you get the "Unable to locate credentials" error. You get this error even if credentials are configured correctly on a provider with lower precedence. After you update your credentials, test the AWS CLI by running an Amazon S3 AWS CLI ...
(I encountered this issue many times - Adding another answer for people that have the same error - from other reasons).
A quick checklist.
Go to Setting -> CI/CD -> Variables and check:
AWS_ACCESS_KEY_ID
& AWS_SECRET_ACCESS_KEY
environment variables exist.protected
- they can only be ran against protected
branches (like master
).If error still occurs:
AWS_SECRET_ACCESS_KEY
doesn't contain any special characters (can lead to strange errors).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With