S3 Object Lambda Access Point: HTTP 301 errors with Ruby application

0

I have a Ruby on Rails application with Active Storage, which uses S3 as the storage service. Active Storage obtains the bucket's information through a storage.yml file, which defines service, region, and bucket for S3. This has been working in production for several years now.

Currently, we are trying to add an S3 Object Lambda Access Point. As this article mentions, Access Point's Alias can be used interchangeably with the bucket name, so we are replacing the bucket name for the AP alias in the bucket field of our storage.yml file.

However, we are getting HTTP 301 errors (we've confirmed that the key exists in the bucket, and that the Lambda function is not being invoked):

2.5.5 :017 > variant.service.exist?(variant.key)
  S3 Storage (115.6ms) Checked if file exists at key: <object-key> (no)
Traceback (most recent call last):
        1: from (irb):17
Aws::S3::Errors::Http301Error (Aws::S3::Errors::Http301Error)

When using the bucket name (instead of the alias), the typical S3 URL for the objects, once presigned, looks like: https://<Bucket name>.s3.<Region>.amazonaws.com/<object-key>/<Signed-URL-Credentials>

We are using the latest version of the aws-sdk-s3 gem, and we have checked that the access point’s alias is correct.

Any help you could provide? Maybe Object Lambda Aliases can't be used with the aws-sdk-s3 gem, even when the article mentions that they can be used as bucket names?

juaniL
asked 10 months ago329 views
1 Answer
0

Hello,

I have not specifically used Active Storage for S3, but when working with Dynamo or other databases I have found that the URL for end points vs access can differ. Given that HTTP 301 errors usually indicate a redirection this may be a good place to start. In the context of AWS S3, this may mean that the request is being made to the wrong endpoint. When using S3 Access Points, I believe the endpoint URL structure is different from the standard S3 bucket URL structure. The standard structure is https://bucket-name.s3.region.amazonaws.com, but for access points, the structure is https://access-point-name-123456789012.s3-accesspoint.region.amazonaws.com.

It's possible that the AWS SDK for Ruby is not correctly handling the Access Point alias and is trying to use the standard bucket URL structure, leading to the 301 redirect error. You might need to manually specify the correct endpoint URL when creating the S3 client in your Ruby code.

Maybe adding a line like:

s3 = Aws::S3::Resource.new(region: 'us-west-2', endpoint: 'https://access-point-name-123456789012.s3-accesspoint.region.amazonaws.com')

Hopefully this can add a starting point!

profile picture
Zac Dan
answered 10 months ago
  • Hi Zac,

    The thing is, with Object Lambda AP Aliases, the expected URL structure is indeed as if it were a bucket, not an Access Point. Citing the AWS article I mentioned before:

    "Aliases [...] are interchangeable with bucket names anywhere you use a bucket name to access data stored in Amazon S3. Therefore, your applications don’t need to know about S3 Object Lambda and can consider the alias to be a bucket name."

    So it should not be an issue with the URL formation in the Ruby AWS SDK, as the URL should have the same format that always worked for us. Hope I made myself clear enough.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions