Answer: D
Options A is incorrect because using Security Groups will not help to allow specific access to the S3 bucket via the VPC endpoint.
Options B is incorrect because using the route tables will not help to allow specific access to the S3 bucket via the VPC endpoint.
Option C is incorrect because it is the bucket policy that needs to be changed and not the IAM policy for restricting S3 buckets access only via a VPC endpoint.
Option D is CORRECT you can use Amazon S3 bucket policies to control access to buckets from specific Amazon Virtual Private Cloud (Amazon VPC) endpoints, or specific VPCs. The bucket policy denies all access to the bucket if the specified endpoint is not being used.
Example bucket policy provided below, just make sure to replace the VPC endpoint ID with an appropriate value for your use case and disable console access to the specified bucket, because console requests don`t originate from the specified VPC endpoint.
{
"Version": "2012-10-17",
"Id": "Policy1415115909152",
"Statement": [
{
"Sid": "Access-to-specific-VPCE-only",
"Principal": "*",
"Action": "s3:*",
"Effect": "Deny",
"Resource": ["arn:aws:s3:::awsexamplebucket1",
"arn:aws:s3:::awsexamplebucket1/*"],
"Condition": {
"StringNotEquals": {
"aws:SourceVpce": "vpce-1a2b3c4d"
}
}
}
]
}
For more information on example bucket policies for VPC endpoints, kindly refer to the following URL:
https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies-vpc-endpoint.html