Skip to content

Commit

Permalink
feat: plat-5576 make vpc optional in api and worker constructs (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
malcyL authored May 10, 2022
1 parent 407a974 commit fdd4527
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export class SimpleAuthenticatedApiStack extends cdk.Stack {
{ topicName: `${prefix}simple-authenticated-api-alarm` }
);

const vpc = ec2.Vpc.fromLookup(this, `${prefix}-vpc`, {
vpcId: "vpc-0155db5e1ab5c28b6",
});
// VPC is optional. To use one, you would look it up as follows:
// const vpc = ec2.Vpc.fromLookup(this, `${prefix}-vpc`, {
// vpcId: "vpc-0155db5e1ab5c28b6",
// });

// Setting a security group is an option. This is an example of importing and using a
// pre existing security group. This one is defined in terraform.
Expand Down Expand Up @@ -61,7 +62,9 @@ export class SimpleAuthenticatedApiStack extends cdk.Stack {
handler: "route",
timeout: cdk.Duration.seconds(30),
securityGroups: lambdaSecurityGroups,
vpc: vpc,
// A VPC is optional. If you need to specify one, you would do so here:
// vpc: vpc,
// vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_NAT },
}
);

Expand All @@ -75,7 +78,9 @@ export class SimpleAuthenticatedApiStack extends cdk.Stack {
handler: "route",
timeout: cdk.Duration.seconds(30),
securityGroups: lambdaSecurityGroups,
vpc: vpc,
// A VPC is optional. If you need to specify one, you would do so here:
// vpc: vpc,
// vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_NAT },
}
);

Expand All @@ -88,8 +93,9 @@ export class SimpleAuthenticatedApiStack extends cdk.Stack {
description: "A simple example API",
stageName: "development", // This should be development / staging / production as appropriate
alarmTopic,
vpc,
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_NAT },
// A VPC is optional. If you need to specify one, you would do so here:
// vpc: vpc,
// vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_NAT },
securityGroups: lambdaSecurityGroups,
domainName: `${prefix}simple-authenticated-api.talis.com`,
certificateArn: STAGING_TALIS_TLS_CERT_ARN,
Expand Down
12 changes: 7 additions & 5 deletions examples/simple-lambda-worker/lib/simple-lambda-worker-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ export class SimpleLambdaWorkerStack extends cdk.Stack {
{ topicName: `${prefix}simple-lambda-worker-alarm` }
);

const vpc = ec2.Vpc.fromLookup(this, `${prefix}-vpc`, {
vpcId: "vpc-0155db5e1ab5c28b6",
});
// VPC is optional. To use one, you would look it up as follows:
// const vpc = ec2.Vpc.fromLookup(this, `${prefix}-vpc`, {
// vpcId: "vpc-0155db5e1ab5c28b6",
// });

// Setting a security group is an option. This is an example of importing and using a
// pre existing security group. This one is defined in terraform.
Expand Down Expand Up @@ -83,8 +84,9 @@ export class SimpleLambdaWorkerStack extends cdk.Stack {
memorySize: 1024,
securityGroups: lambdaSecurityGroups,
timeout: cdk.Duration.seconds(30),
vpc: vpc,
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_NAT },
// A VPC is optional. If you need to specify one, you would do so here:
// vpc: vpc,
// vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_NAT },
policyStatements: [
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
Expand Down
3 changes: 2 additions & 1 deletion lib/authenticated-api/authenticated-api-function-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export interface AuthenticatedApiFunctionProps {
environment?: { [key: string]: string };
handler: string;
timeout: cdk.Duration;
vpc: ec2.IVpc;
vpc?: ec2.IVpc;
vpcSubnets?: ec2.SubnetSelection;
securityGroups: Array<ec2.ISecurityGroup>;
memorySize?: number;
}
2 changes: 1 addition & 1 deletion lib/authenticated-api/authenticated-api-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AuthenticatedApiFunction extends lambdaNode.NodejsFunction {
timeout: props.timeout,
securityGroups: props.securityGroups,
vpc: props.vpc,
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_NAT },
vpcSubnets: props.vpcSubnets,
});
}
}
4 changes: 2 additions & 2 deletions lib/authenticated-api/authenticated-api-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export interface AuthenticatedApiProps {
stageName: string;
routes: Array<RouteLambdaProps>;
securityGroups?: Array<ec2.ISecurityGroup>;
vpc: ec2.IVpc;
vpcSubnets: ec2.SubnetSelection;
vpc?: ec2.IVpc;
vpcSubnets?: ec2.SubnetSelection;
domainName: string;
certificateArn: string;
corsDomain?: string[];
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda-worker/lambda-worker-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export interface LambdaWorkerProps {
retryAttempts?: number;
securityGroups?: Array<ec2.ISecurityGroup>;
timeout: cdk.Duration;
vpc: ec2.IVpc;
vpcSubnets: ec2.SubnetSelection;
vpc?: ec2.IVpc;
vpcSubnets?: ec2.SubnetSelection;
};

// Queue Properties
Expand Down

0 comments on commit fdd4527

Please sign in to comment.