Restrict S3 bucket Access to VPC

Allow access to S3 bucket only from VPC
Currently I am evaluating options to lockdown permissions to my S3 Buckets as part of Security Enhancements.
These are the steps I followed to lock down S3 Bucket access only to my VPC.

Create VPC End Points
VPC End Points Screen Shot

Create VPC End Points
Create VPC End Points

Attach the S3 Bucket Policy to Restrict Access 

	"Version": "2012-10-17",
	"Id": "Policy123456789",
	"Statement": [
			"Sid": "Stmt123456789",
			"Effect": "Deny",
			"Principal": "*",
			"Action": "s3:*",
			"Resource": "arn:aws:s3:::example-confidential/*",
			"Condition": {
				"StringNotEquals": {
					"aws:sourceVpc": "vpc-2f2b202b"
AWS Policy Generator
AWS Policy Generator

Access the Buckets Outside VPC
Once you have attached the policy, if you access the S3 Files through console not being on VPC , you will receive the error.

Access Denied


Access the Buckets from VPC
If you log into a EC2 Instance which is hosted on VPC , you will be able to access the s3 Bucket.

SSH Into your EC2 Machine and verify your VPC through Instance Meta Data Store.

[ec2-user]# curl


[ec2-user]# curl


If you execute s3 commands to access the bucket, you will be able to access the S3 Bucket without access denied error.

aws s3 ls example-confidential
aws s3 cp s3:://example-confidential/SampleConfidentialFile.txt  SampleConfidentialFile.txt

References :

AWS Documentation for VPC Endpoints

Adding S3 Policy to Restrict Access to specific VPC Only

AWS Policy Generator

AWS Blog Post on VPC Endpoints

IAM Policy Elements Reference

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *