Skip to content

EC2 instances in a private subnet to access S3 but avoid internet exposure.

0

Dear Team,

Please help me done this task. Give me the instruction that i want to get more exposure

You want EC2 instances in a private subnet to access S3 but avoid internet exposure.

Thanks, MahendraKumar V

2 Answers
0

If your buckets are in the same region as your EC2s, you can use a S3 Gateway Endpoint https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html

If you want to access buckets in another region, you willl need to look at VPC Endpoints with VPC Peering to another region https://docs.aws.amazon.com/AmazonS3/latest/userguide/privatelink-interface-endpoints.html

EXPERT
answered 9 months ago
EXPERT
reviewed 9 months ago
0

Hello Mahendra,

You can achieve that through VPC End point For that follow these steps.

  • Create a VPC Endpoint by selecting S3 as service and choose the VPC which holds the private subnet.
  • Attach the VPC endpoint to Route table of your private subnet.
  • To ensure that only EC2 instances in your VPC can access the S3 bucket, update the S3 bucket policy:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": ["arn:aws:s3:::your-bucket-name/*"],
      "Condition": {
        "StringEquals": {
          "aws:SourceVpc": "vpc-12345678910"
        }
      }
    }
  ]
}

By this process you can achieve the access of S3 objects from Private EC2 Instance.

References: https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html

Thank you.

EXPERT
answered 9 months ago

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.