How to use the @aws-cdk/aws-ec2.Vpc function in @aws-cdk/aws-ec2

To help you get started, we’ve selected a few @aws-cdk/aws-ec2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github customink / activerecord-aurora-serverless-adapter / test / aurora-serverless / lib / aurora-serverless-stack.ts View on Github external
constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    // VPC

    const vpc = new Vpc(this, "Vpc", {
      cidr: "10.0.0.0/16",
      natGateways: 0,
      subnetConfiguration: [
        { name: "aasa_isolated", subnetType: SubnetType.ISOLATED }
      ]
    });
    const subnetIds: string[] = [];
    vpc.isolatedSubnets.forEach(subnet => {
      subnetIds.push(subnet.subnetId);
    });

    // SUBNET GROUP

    const dbSubnetGroup: CfnDBSubnetGroup = new CfnDBSubnetGroup(
      this,
      "AuroraSubnetGroup",
github duo-labs / cloudmapper / auditor / lib / cloudmapperauditor-stack.js View on Github external
constructor(scope, id, props) {
    super(scope, id, props);

    // Load config file
    var config = yaml.safeLoad(fs.readFileSync('./s3_bucket_files/cdk_app.yaml', 'utf8'));

    if (config['s3_bucket'] == 'MYCOMPANY-cloudmapper') {
      console.log("You must configure the CDK app by editing ./s3_bucket_files/cdk_app.yaml");
      process.exit(1);
    }

    // Create VPC to run everything in. We make this public just because we don't
    // want to spend $30/mo on a NAT gateway.
    const vpc = new ec2.Vpc(this, 'CloudMapperVpc', {
        maxAzs: 1,
        natGateways: 0,
        subnetConfiguration: [
          {
            name: 'Public',
            subnetType: ec2.SubnetType.PUBLIC
          }
        ]
    });

    // Define the ECS task
    const cluster = new ecs.Cluster(this, 'Cluster', { vpc });

    const taskDefinition = new ecs.FargateTaskDefinition(this, 'taskDefinition', {});

    taskDefinition.addContainer('cloudmapper-container', {
github aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / fargate / load-balanced-fargate-service-applet.ts View on Github external
constructor(scope: cdk.Construct, id: string, props: LoadBalancedFargateServiceAppletProps) {
    super(scope, id, props);

    const vpc = new Vpc(this, 'MyVpc', { maxAZs: 2 });
    const cluster = new Cluster(this, 'Cluster', { vpc });

    let domainZone;
    if (props.domainZone) {
      domainZone = new HostedZoneProvider(this, { domainName: props.domainZone }).findAndImport(this, 'Zone');
    }
    let certificate;
    if (props.certificate) {
      certificate = Certificate.fromCertificateArn(this, 'Cert', props.certificate);
    }

    // Instantiate Fargate Service with just cluster and image
    new LoadBalancedFargateService(this, "FargateService", {
      cluster,
      cpu: props.cpu,
      containerPort: props.containerPort,
github aws-samples / aws-reinvent-2019-trivia-game / trivia-backend / infra / codedeploy-blue-green / infra-setup.ts View on Github external
constructor(parent: cdk.App, name: string, props: TriviaBackendStackProps) {
    super(parent, name, props);

    // Network infrastructure
    const vpc = new Vpc(this, 'VPC', { maxAzs: 2 });
    const serviceSG = new SecurityGroup(this, 'ServiceSecurityGroup', { vpc });

    // Lookup pre-existing TLS certificate
    const certificateArn = StringParameter.fromStringParameterAttributes(this, 'CertArnParameter', {
      parameterName: 'CertificateArn-' + props.domainName
    }).stringValue;

    // Load balancer
    const loadBalancer = new ApplicationLoadBalancer(this, 'ServiceLB', {
      vpc,
      internetFacing: true
    });
    serviceSG.connections.allowFrom(loadBalancer, Port.tcp(80));

    const domainZone = HostedZone.fromLookup(this, 'Zone', { domainName: props.domainZone });
    new ARecord(this, "DNS", {
github aws-samples / aws-reinvent-2019-trivia-game / trivia-backend / infra / cdk / ecs-service.ts View on Github external
constructor(parent: cdk.App, name: string, props: TriviaBackendStackProps) {
    super(parent, name, props);

    // Network infrastructure
    const vpc = new Vpc(this, 'VPC', { maxAzs: 2 });
    const cluster = new Cluster(this, 'Cluster', {
      clusterName: props.domainName.replace(/\./g, '-'),
      vpc
    });

    // Configuration parameters
    const domainZone = HostedZone.fromLookup(this, 'Zone', { domainName: props.domainZone });
    const imageRepo = Repository.fromRepositoryName(this, 'Repo', 'reinvent-trivia-backend');
    const tag = (process.env.IMAGE_TAG) ? process.env.IMAGE_TAG : 'latest';
    const image = ContainerImage.fromEcrRepository(imageRepo, tag)

    // Lookup pre-existing TLS certificate
    const certificateArn = StringParameter.fromStringParameterAttributes(this, 'CertArnParameter', {
      parameterName: 'CertificateArn-' + props.domainName
    }).stringValue;
    const certificate = Certificate.fromCertificateArn(this, 'Cert', certificateArn);
github nathanpeck / greeter-cdk / index.js View on Github external
constructor(parent, id, props) {
    super(parent, id, props);

    const vpc = new ec2.Vpc(this, 'GreetingVpc', { maxAZs: 2 });

    // Create an ECS cluster
    const cluster = new ecs.Cluster(this, 'Cluster', { vpc });

    // Add capacity to it
    cluster.addCapacity('greeter-capacity', {
      instanceType: new ec2.InstanceType('t3.xlarge'),
      minCapacity: 3,
      maxCapacity: 3
    });

    // Name service
    const nameTaskDefinition = new ecs.Ec2TaskDefinition(this, 'name-task-definition', {});

    const nameContainer = nameTaskDefinition.addContainer('name', {
      image: ecs.ContainerImage.fromRegistry('nathanpeck/name'),
github aws-samples / aws-cdk-changelogs-demo / changelogs-md.js View on Github external
constructor(parent, id, props) {
    super(parent, id, props);

    // Network to run everything in
    const vpc = new ec2.Vpc(this, 'NpmFollowerVpc', {
      maxAZs: 2,
      natGateways: 1
    });

    // A table to store the list of changelogs and their metadata in
    const changelogsTable = new dynamodb.Table(this, 'Changelogs', {
      partitionKey: { name: 'changelog', type: dynamodb.AttributeType.STRING },
      billingMode: dynamodb.BillingMode.Provisioned
    });

    const readScaling = changelogsTable.autoScaleReadCapacity({
      minCapacity: 211,
      maxCapacity: 300
    });

    readScaling.scaleOnUtilization({
github aws / aws-cdk / packages / @aws-cdk / aws-eks-legacy / lib / cluster.ts View on Github external
constructor(scope: Construct, id: string, props: ClusterProps = { }) {
    super(scope, id, {
      physicalName: props.clusterName,
    });

    this.node.addWarning(`The @aws-cdk/aws-eks-legacy module will no longer be released as part of the AWS CDK starting March 1st, 2020. Please refer to https://github.com/aws/aws-cdk/issues/5544 for upgrade instructions`);

    const stack = Stack.of(this);

    this.vpc = props.vpc || new ec2.Vpc(this, 'DefaultVpc');
    this.version = props.version;

    this.tagSubnets();

    this.role = props.role || new iam.Role(this, 'ClusterRole', {
      assumedBy: new iam.ServicePrincipal('eks.amazonaws.com'),
      managedPolicies: [
        iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSClusterPolicy'),
        iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSServicePolicy'),
      ],
    });

    const securityGroup = props.securityGroup || new ec2.SecurityGroup(this, 'ControlPlaneSecurityGroup', {
      vpc: this.vpc,
      description: 'EKS Control Plane Security Group',
    });
github aws / aws-cdk / packages / @aws-cdk / aws-ecs / lib / cluster.ts View on Github external
super(scope, id, {
      physicalName: props.clusterName,
    });

    const cluster = new CfnCluster(this, 'Resource', {
      clusterName: this.physicalName,
    });

    this.clusterArn = this.getResourceArnAttribute(cluster.attrArn, {
      service: 'ecs',
      resource: 'cluster',
      resourceName: this.physicalName,
    });
    this.clusterName = this.getResourceNameAttribute(cluster.ref);

    this.vpc = props.vpc || new ec2.Vpc(this, 'Vpc', { maxAzs: 2 });

    this._defaultCloudMapNamespace = props.defaultCloudMapNamespace !== undefined
      ? this.addDefaultCloudMapNamespace(props.defaultCloudMapNamespace)
      : undefined;

    this._autoscalingGroup = props.capacity !== undefined
      ? this.addCapacity("DefaultAutoScalingGroup", props.capacity)
      : undefined;
  }