I'm a beginner with AWS and I'm trying to connect to S3. I have a really simple export but I'm getting error message:
{"message":"Inaccessible host: `legal-systems-staging.s3.eu-central-1.amazonaws.com'. This service may not be available in the `eu-central-1' region.","code":"UnknownEndpoint","region":"eu-central-1","hostname":"legal-systems-staging.s3.eu-central-1.amazonaws.com","retryable":true,"originalError":{"message":"getaddrinfo ENOTFOUND legal-systems-staging.s3.eu-central-1.amazonaws.com
To connect I have this code:
const AWS = require('aws-sdk');
module.exports = function(customENV){ return function(req, res) {
//get ENV variables
const aws_accessKeyId = customENV.access_key;
const aws_secretAccessKey = customENV.secret_access_key;
const aws_region = customENV.s3_region;
const aws_bucket = customENV.s3_bucket;
//configuring the AWS environment
AWS.config.update({
region: aws_region,
accessKeyId: aws_accessKeyId,
secretAccessKey: aws_secretAccessKey
});
new AWS.S3().getObject({ Bucket: aws_bucket, Key: req.body.template }, function(err, data) {
if (!err) {
res.send('good');
} else {
res.send(err);
}
});
}};
Bucket in S3 Management Console has region EU (Frankfurt) and according this list it should be right.
Credential are correct. What am I doing wrong?
This is going to sound really stupid, but I had that error because, in my .env
file, I had the values of my bucket and region mixed up.
After switching their values, my code was working again.
Check the access with AWS CLI tools. If you can access via AWS CLI (list, upload, sign URLs, delete, etc), but not via your code, chances are that you are having a similar problem.
Hope this helps someone like me.
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