Error when trying to upload object to S3 through Lambda with AWS SDK, InvalidAccessPointARN: Access point ARN region is empty

Viewed 1248

I'm trying to upload a txt to S3. The lambda function has the following policies:

  • AmazonS3FullAccess
  • AWSLambdaBasicExecutionRole

And this is the code

const AWS = require('aws-sdk');
const s3 = new AWS.S3();

exports.handler = async (event) => {

  const bucketName = 'arn:aws:s3:::0dd839423855435';
  const keyName = 'test.txt';
  const content = 'Test';

  const params = {
    'Bucket': bucketName,
    'Key': keyName,
    'Body': content
  };

  try {
    const data = await s3.putObject(params).promise();
  } catch (err) {
    console.log(err)
  }
}

And this the error

InvalidAccessPointARN: Access point ARN region is empty
    at Request.validateAccessPointArn (/var/runtime/node_modules/aws-sdk/lib/services/s3.js:201:28)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at Request.runTo (/var/runtime/node_modules/aws-sdk/lib/request.js:403:15)
    at /var/runtime/node_modules/aws-sdk/lib/request.js:792:12
    at new Promise (<anonymous>)
    at Request.promise (/var/runtime/node_modules/aws-sdk/lib/request.js:778:12) {
  code: 'InvalidAccessPointARN',
  time: 2020-06-29T23:00:43.979Z

I don't know what I am doing bad. Also, I would like to avoid creating an access point.

1 Answers

So the first thing I guess you are using terraform or something like Infrastructure as Code.

That's why your bucket name is the randomly generated number: 0dd839423855435

So you do not have to use arn (arn:aws:s3:::0dd839423855435) as bucket name, instead of using arn use just and just only bucket name or in other words this is the id of the bucket which is this 0dd839423855435 in your case.

Lambda and S3 should be located in same region.

In case you created s3 with terraform then you can output the arn or id by doing this:

For ARN:

output "your-bucket-arn" {
  value = aws_s3_bucket.your-bucket.arn
}

For ID:

output "your-bucket-id" {
  value = aws_s3_bucket.your-bucket.id
}
Related