How can I verify that boto3.client('s3')
in EC2 is using VPC endpoint?
In AWS, I have a created VPC Endpoint (service=s3, type=gateway). From what I understand, boto automagically selects its client(endpoint_url)
. I am ingesting terabytes of data, so I don’t want to get charged egress fees when writing from EC2 to S3.
Desktop
>>> import boto3
>>> conn = boto3.client('s3')
>>> conn._endpoint
"s3(https://s3.amazonaws.com)"
AWS Batch Job – Fargate within VPC
I want more information here. Is it pointed to my VPC Endpoint ID/ARN?
>>> import boto3
>>> conn = boto3.client('s3')
>>> conn._endpoint
"s3(https://s3.amazonaws.com)"
Here, boto3 acknowledges the existence of my VPC Endpoint
>>> from pprint import pprint
>>> import boto3
>>> conn = boto3.client('ec2') #<-- note 'ec2' not 's3'
>>> resp = conn.c.describe_vpc_endpoints()
>>> pprint(resp['VpcEndpoints'])
2
Answers
S3 Logs
Another indirect solution without use of boto
Using S3 logs, I am able to see the IP addresses of requests made to S3. The IP matches the
172.31.0.0/16
CIDR of my VPC as opposed to a public IP, so I conclude that my endpoint/gateway is working.Process
Supplemental Info
The easiest way I can think of is to use bucket policies. You can restrict bucket access to a specific endpoint. If your requests still work after the bucket policy is applied, then it means your requests are going through the VPC endpoint.
Example: Restrict access to a specific endpoint