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

vpc-endpoint-service.tf#L1
resource "aws_vpc_endpoint_service" "mktsvc" {
  acceptance_required        = false
  network_load_balancer_arns = [aws_lb.fargate.arn]
  allowed_principals = var.vpc_endpointsvc_allowed_principals
}
vpc-endpoint-service.tf#L1
resource "aws_vpc_endpoint_service" "mktsvc" {
  acceptance_required        = false
  network_load_balancer_arns = [aws_lb.fargate.arn]
  allowed_principals = var.vpc_endpointsvc_allowed_principals
}

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

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).

risk-label

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.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

template-vpc-endpoint-service.yml#L31
    Type: AWS::EC2::VPCEndpointService
    Properties:
      AcceptanceRequired: true
      NetworkLoadBalancerArns:
        - !Ref NetworkLoadBalancer

vpc-endpoint-ec2-privatelink.yml#L260
    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:
lb.yml#L259
    Type: AWS::EC2::VPCEndpointService
    Properties:
      AcceptanceRequired: false
      NetworkLoadBalancerArns:
      - !Ref WebLb

vpc-endpoint-privatelink-service.yml#L247
    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

1.GWLBVPC.yml#L218
    Type: AWS::EC2::VPCEndpointService
    Properties:
      GatewayLoadBalancerArns:
        - !Ref GWLB
      AcceptanceRequired: false

integ.vpc-endpoint-service.expected.json#L4
      "Type": "AWS::EC2::VPCEndpointService",
      "Properties": {
        "NetworkLoadBalancerArns": [
          "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
        ],
        "AcceptanceRequired": false
integ.vpc-endpoint-service.expected.json#L4
      "Type": "AWS::EC2::VPCEndpointService",
      "Properties": {
        "NetworkLoadBalancerArns": [
          "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
        ],
        "AcceptanceRequired": false
integ.vpc-endpoint-service.expected.json#L4
      "Type": "AWS::EC2::VPCEndpointService",
      "Properties": {
        "NetworkLoadBalancerArns": [
          "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
        ],
        "AcceptanceRequired": false
integ.vpc-endpoint-service.expected.json#L4
      "Type": "AWS::EC2::VPCEndpointService",
      "Properties": {
        "NetworkLoadBalancerArns": [
          "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
        ],
        "AcceptanceRequired": false
integ.vpc-endpoint-service.expected.json#L4
      "Type": "AWS::EC2::VPCEndpointService",
      "Properties": {
        "NetworkLoadBalancerArns": [
          "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
        ],
        "AcceptanceRequired": false

Parameters

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.