amazon web services - Access private S3 bucket from Nginx running on EC2 - Stack Overflow

admin2025-04-28  2

I have a bucket with public access blocked that I need to access from nginx running on an EC2 instance.

The EC2 instance profile has the correct access but for nginx to access S3 I would need to pass the credentials on every request. I will investigate nginx caching and the lifetime of the AWS credentials but I wanted to get some thoughts on best practice for this scenario.

Allowing access on the bucket policy level is an option and might be easier.

I have a bucket with public access blocked that I need to access from nginx running on an EC2 instance.

The EC2 instance profile has the correct access but for nginx to access S3 I would need to pass the credentials on every request. I will investigate nginx caching and the lifetime of the AWS credentials but I wanted to get some thoughts on best practice for this scenario.

Allowing access on the bucket policy level is an option and might be easier.

Share Improve this question asked Jan 8 at 13:40 Sadha MoodleySadha Moodley 32 bronze badges 3
  • 1 Refer Managing Amazon S3 access with VPC endpoints and S3 Access Points. This is the best practice to access AWS services privately without going through internet gateway. – Ankush Jain Commented Jan 8 at 13:46
  • Perhaps nginxinc/nginx-s3-gateway? – jarmod Commented Jan 8 at 13:46
  • Thanks @jarmod, nginx-s3-gateway is doing what I required. Thanks for the suggestion, they actually have a discussion about this specific problem as well – Sadha Moodley Commented Jan 15 at 11:06
Add a comment  | 

1 Answer 1

Reset to default 0

One option is to configure NGINX as an authenticating and caching gateway for AWS S3 which, among other things:

allows you to proxy a private S3 bucket without requiring users to authenticate to it. Within the proxy layer, additional functionality can be configured such as:

  • Listing the contents of a S3 bucket
  • Providing an authentication gateway using an alternative authentication system to S3

NGINX offers such a gateway configuration at nginxinc/nginx-s3-gateway.

转载请注明原文地址:http://anycun.com/QandA/1745853517a91250.html