You can create a gateway endpoint for Amazon S3 using the AWS CLI. Here’s an example of a bash script that creates a gateway endpoint for S3:
#!/bin/bash # Set the AWS CLI region aws configure set default.region us-west-2 # Define the VPC ID and the subnet IDs vpc_id="vpc-12345678" subnet_ids="subnet-12345678 subnet-23456789" # Create the gateway endpoint for Amazon S3 aws ec2 create-vpc-endpoint \ --vpc-id vpc-1a2b3c4d \ --service-name com.amazonaws.us-east-1.s3 \ --route-table-ids rtb-11aa22bb
In this example, replace
vpc-12345678 with the ID of the VPC in which you want to create the endpoint, replace
subnet-23456789 with the IDs of the subnets in which to create the endpoint, and replace
sg-12345678 with the ID of the security group to associate with the endpoint.
aws ec2 create-vpc-endpoint command creates the gateway endpoint for Amazon S3, using the specified VPC ID, subnet IDs, security group ID, and endpoint type. Once the endpoint is created, you can use it to access Amazon S3 resources from instances within your VPC without using the public internet.
Note: You will need to have the necessary IAM permissions to create VPC endpoints in order to run this script. You can find more information on the necessary IAM permissions in the AWS documentation.