Security Group-Restricted Outbound Access to AWS Gateway VPC endpoints-S3 and DynamoDB

AWS gateway VPC endpoint allows services in the VPC to connect to S3 and DynamoDB privately. In order to access AWS gateway endpoint, security groups and NACLs in the VPC should allow outbound connection to gateway VPC endpoints. By default, security group allows all the outbound access but the best practice is to restrict outbound access and allow only required connection. Here we focus on how to add a outbound rule to security group that allows access to S3 and DynamoDB gateway endpoint using cloud formation and lambda function.

For example, Requirement is that AWS Fargate service needs access to S3 and DynamoDB via private AWS connection as shown in the diagram below and Fargate security group restricts outbound access. Existing AWS ECS cluster creation CF template needs to be updated with new security group outbound rules to allow access to S3 and DynamoDB gateway endpoint.

Solutions: To add outbound access rule to gateway endpoint, first we need to get the AWS prefix list ID(IP address ranges for an AWS service) and then use it in the security group outbound rules as destination.

This can be automated via cloud formation as below.

  1. Use the following CF template to create lambda function to get AWS prefix list ID for S3 and DynamoDB gateway endpoints.

2. Add the above lambda function as custom resources in CF template and create security group outbound rules as follow.

Above provided cloud formation templates will automate the creation of security group outbound rules to allow access to S3 and DynamoDB gateway endpoint. As a security best practice, it is highly recommended to restrict access to outbound connection for critical services in VPC at security group level.

Once the stack created successfully with above CF template, security group outbound rules will appear as below.

--

--

AWS APN Ambassador | Solutions Architect | AWS Certified Pro | GCP Certified Pro | Azure Certified Expert | AWS Certified Security & Machine Learning Specialty

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nanthan Rasiah

AWS APN Ambassador | Solutions Architect | AWS Certified Pro | GCP Certified Pro | Azure Certified Expert | AWS Certified Security & Machine Learning Specialty