Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to locate credentials - Gitlab Pipeline for S3

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?

like image 532
Katana24 Avatar asked Apr 13 '18 09:04

Katana24


People also ask

How do you fix unable to locate credentials you can configure credentials by running AWS configure?

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.

Where do I find my AWS credentials?

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.

Why am I getting an “unable to locate credentials” error in S3?

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.

How do I add AWS credentials to GitLab CI?

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.

Should I use GitLab CI with S3?

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.

Why am I getting'unable to locate credentials'error in AWS?

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 ...


1 Answers

(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:

  1. If both AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY environment variables exist.
  2. If both names are spelled right.
  3. If their state is defined as protected - they can only be ran against protected branches (like master).

If error still occurs:

  1. Make sure the access keys still exist and active on your account.
  2. Delete current environment variables and replace them with new generated access keys and make sure AWS_SECRET_ACCESS_KEY doesn't contain any special characters (can lead to strange errors).
like image 54
RtmY Avatar answered Sep 20 '22 12:09

RtmY