AWS Amazon EC2 Endpoint Service
This page shows how to write Terraform and CloudFormation for Amazon EC2 Endpoint Service and write them securely.
aws_vpc_endpoint_service (Terraform)
The Endpoint Service in Amazon EC2 can be configured in Terraform with the resource name aws_vpc_endpoint_service
. The following sections describe 2 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_vpc_endpoint_service" "mktsvc" {
acceptance_required = false
network_load_balancer_arns = [aws_lb.fargate.arn]
allowed_principals = var.vpc_endpointsvc_allowed_principals
}
resource "aws_vpc_endpoint_service" "mktsvc" {
acceptance_required = false
network_load_balancer_arns = [aws_lb.fargate.arn]
allowed_principals = var.vpc_endpointsvc_allowed_principals
}
Parameters
-
acceptance_required
required - bool -
allowed_principals
optional computed - set of string -
arn
optional computed - string -
availability_zones
optional computed - set of string -
base_endpoint_dns_names
optional computed - set of string -
gateway_load_balancer_arns
optional - set of string -
id
optional computed - string -
manages_vpc_endpoints
optional computed - bool -
network_load_balancer_arns
optional - set of string -
private_dns_name
optional computed - string -
private_dns_name_configuration
optional computed - list of object -
service_name
optional computed - string -
service_type
optional computed - string -
state
optional computed - string -
tags
optional - map from string to string
Explanation in Terraform Registry
Provides a VPC Endpoint Service resource. Service consumers can create an Interface VPC Endpoint to connect to the service.
NOTE on VPC Endpoint Services and VPC Endpoint Service Allowed Principals: Terraform provides both a standalone VPC Endpoint Service Allowed Principal resource and a VPC Endpoint Service resource with an
allowed_principals
attribute. Do not use the same principal ARN in both a VPC Endpoint Service resource and a VPC Endpoint Service Allowed Principal resource. Doing so will cause a conflict and will overwrite the association.
Tips: Best Practices for The Other AWS Amazon EC2 Resources
In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_default_vpc
Ensure to avoid using default VPC
It is better to define the own VPC and use it.
aws_network_acl_rule
Ensure your network ACL rule blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
aws_ebs_volume
Ensure to use a customer-managed key for EBS volume encryption
It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).
aws_instance
Ensure to avoid storing AWS access keys in user data
It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.
aws_security_group
Ensure your security group blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
AWS::EC2::VPCEndpointService (CloudFormation)
The VPCEndpointService in EC2 can be configured in CloudFormation with the resource name AWS::EC2::VPCEndpointService
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::EC2::VPCEndpointService
Properties:
AcceptanceRequired: true
NetworkLoadBalancerArns:
- !Ref NetworkLoadBalancer
Type: AWS::EC2::VPCEndpointService
Properties:
AcceptanceRequired: false # if you don't set it or set to true, you have to manually accept endpoint requests
NetworkLoadBalancerArns:
- !Ref NLB
Vpc2Endpoint:
Type: AWS::EC2::VPCEndpointService
Properties:
AcceptanceRequired: false
NetworkLoadBalancerArns:
- !Ref WebLb
Type: AWS::EC2::VPCEndpointService
Properties:
AcceptanceRequired: true # if you don't set it or set to true, you have to manually accept endpoint requests
NetworkLoadBalancerArns:
- !Ref NLB
Type: AWS::EC2::VPCEndpointService
Properties:
GatewayLoadBalancerArns:
- !Ref GWLB
AcceptanceRequired: false
"Type": "AWS::EC2::VPCEndpointService",
"Properties": {
"NetworkLoadBalancerArns": [
"arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
],
"AcceptanceRequired": false
"Type": "AWS::EC2::VPCEndpointService",
"Properties": {
"NetworkLoadBalancerArns": [
"arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
],
"AcceptanceRequired": false
"Type": "AWS::EC2::VPCEndpointService",
"Properties": {
"NetworkLoadBalancerArns": [
"arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
],
"AcceptanceRequired": false
"Type": "AWS::EC2::VPCEndpointService",
"Properties": {
"NetworkLoadBalancerArns": [
"arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
],
"AcceptanceRequired": false
"Type": "AWS::EC2::VPCEndpointService",
"Properties": {
"NetworkLoadBalancerArns": [
"arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
],
"AcceptanceRequired": false
Parameters
-
NetworkLoadBalancerArns
optional - List -
AcceptanceRequired
optional - Boolean -
GatewayLoadBalancerArns
optional - List
Explanation in CloudFormation Registry
Creates a VPC endpoint service configuration to which service consumers (AWS accounts, IAM users, and IAM roles) can connect.
To create an endpoint service configuration, you must first create one of the following for your service:+ A Network Load Balancer. Service consumers connect to your service using an interface endpoint.
- A Gateway Load Balancer. Service consumers connect to your service using a Gateway Load Balancer endpoint.
For more information, see VPC Endpoint Services in the Amazon Virtual Private Cloud User Guide.
Frequently asked questions
What is AWS Amazon EC2 Endpoint Service?
AWS Amazon EC2 Endpoint Service is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Amazon EC2 Endpoint Service?
For Terraform, the dexterchan/Terraform_CrossRegionVPCPeering and dexterchan/Terraform_CrossRegionVPCPeering source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the stefanycos/aws-cloudformation-vpc-endpoints, dgaydukov/cert-aws and YAwasom/project source code examples are useful. See the CloudFormation Example section for further details.