I've got an express service that is trying to write an object to an s3 bucket but I'm getting the following error:
Missing credentials in config
I'm assuming my AWS role locally which sets my credentials in .aws/credentials
then in my Dockerfile I am copying them into my container.
RUN mkdir "/home/node/.aws" && touch "/home/node/.aws/config" && touch "/home/node/.aws/credentials"
RUN echo "${AWS_CREDENTIALS}" > "/home/node/.aws/credentials"
The documentation says:
The SDK automatically detects AWS credentials set as variables in your environment and uses them for SDK requests, eliminating the need to manage credentials in your application. The environment variables that you set to provide your credentials are:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_SESSION_TOKEN (optional)
So I don't have to manually manage my credentials when using the sdk?
Currently the code for writing to the s3 bucket:
import s3 from 'aws-sdk/clients/s3';
const s3Client = new s3({region: process.env['region']});
async upload() {
const params = {
Bucket: process.env['bucket'],
Key: 'test.json',
Body: somejsonfile
}
const res = s3Client.upload(params).promise();
return results;
}
CodePudding user response:
Is node the right user that execute this code?
Is the file /home/node/.aws/credentials
looks like something like that:
[default]
aws_access_key_id = <AAK>
aws_secret_access_key = <ASK>
To debug, you can try try the following: You can try to add your AWS credentials directly in the code like that:
AWS.config.update({
accessKeyId: "<AAK>",
secretAccessKey: "<ASK>",
"region": "<REGION>"
});
Alternatively, you can try to delete /home/node/.aws/credentials
file and move the credentials to /home/node/.aws/config
file instead:
[default]
region=<REGION>
output=json
aws_access_key_id = <AAK>
aws_secret_access_key = <ASK>
And alternatively you can try to add credentials and region as env variables in your Dockerfile:
ENV AWS_ACCESS_KEY_ID=<AAK>
ENV AWS_SECRET_ACCESS_KEY=<ASK>
ENV AWS_DEFAULT_REGION=<REGION>