Skip to content

VPC with private subnet, using Nat Instance not connected to the internet. #7459

@icecold21

Description

@icecold21

I created a VPC Stack using AWS CDK, which has 3 public subnets, 3 private subnets, and 3 isolated subnets. And use natInstance as an internet provider. But EC2 instances in private subnet were not able to connect to the internet.

Reproduction Steps

This AMI: ami-01514bb1776d5c018 is ap-southeast-1 ami for NatInstance.

import { Construct, Stack, StackProps } from "@aws-cdk/core";
import { Vpc, SubnetType, GenericLinuxImage, NatProvider, InstanceType } from "@aws-cdk/aws-ec2";

interface EnvProps {
}

export class VpcStackTestNat extends Stack {
  public readonly vpc: Vpc;

  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);
    this.vpc = new Vpc(this, 'VpcStackTestNat', {
      maxAzs: 3,
      cidr: '10.0.0.0/16',
      enableDnsHostnames: true,
      enableDnsSupport: true,
      natGatewayProvider: NatProvider.instance({
        instanceType: new InstanceType('t3.nano'),
        machineImage: new GenericLinuxImage({
          'ap-southeast-1': 'ami-01514bb1776d5c018'
        }),
        keyName: 'nat-instance-key',
      }),
      natGateways: 1,
      subnetConfiguration: [
        {
          subnetType: SubnetType.PUBLIC,
          name: 'Ingress',
          cidrMask: 22,
        },
        {
          cidrMask: 22,
          name: 'Application',
          subnetType: SubnetType.PRIVATE,
        },
        {
          cidrMask: 22,
          name: 'Database',
          subnetType: SubnetType.ISOLATED,
        }
      ]
    });
  }
}

Error Log

Ping not success
[ec2-user@ip-10-0-16-205 ~]$ ping google.com
PING google.com (74.125.68.138) 56(84) bytes of data.
----- empty -----

Environment

  • CLI Version :1.31.0 (build 8f3ac79)
  • Framework Version: 1.31.0
  • OS : Mac OS
  • Language : TypeScript

Other


This is 🐛 Bug Report

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-ec2Related to Amazon Elastic Compute CloudbugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.p2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions