Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda Vpc placement #817

Closed
IndikaUdagedara opened this issue Oct 1, 2018 · 1 comment
Closed

Lambda Vpc placement #817

IndikaUdagedara opened this issue Oct 1, 2018 · 1 comment

Comments

@IndikaUdagedara
Copy link

IndikaUdagedara commented Oct 1, 2018

How does the VpcPlacement property of Function() map to VpcConfig in Lambda cloudformation resource?

VpcConfig accepts multiple subnets but VpcPlacement accepts only a single subnet (in SubnetName). May be I've got it wrong. Would be clearer if there's a cdk example of a Lambda placed in an Vpc. I think a fairly common scenario is placing a Lambda in an existing Vpc where the Vpc may not have been cloudformed (so the cdk cloudformation import will not work) . An example of that would be great.

@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 1, 2018

A subnet name selects all subnets created with that name in the subnetConfiguration set when creating the VPC. This setting is useful if you have multiple subnets of the same type, otherwise it's probably preferable to use subnetType to select the type you want (Public or Private).

Placing things in VPCs that weren't created using the CDK is not currently supported, although you can achieve the behavior by passing in matching parameters in the import properties: https://github.com/awslabs/aws-cdk/blob/master/packages/%40aws-cdk/aws-ec2/lib/vpc-ref.ts#L247

For example, if you have a public and private subnet and you want to place in the private subnet:

const vpc = ec2.VpcNetworkRef.import(this, 'VPC', {
  vpcId: 'vpc-12345',
  availabilityZones: ['us-east-1a', 'us-east-1b']
  publicSubnetIds: ['subnet-4381', 'subnet-123'],
  privateSubnetIds: ['subnet-1425', 'subnet-86845'],
});

new lambda.Function(this, 'Lambda', {
  vpc: vpc,
  vpcPlacement: { subnetType: ec2.subnetType.Private }
});

Private is the default, btw, so you don't need to specify that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants