Skip to content

Commit

Permalink
Merge pull request #193 from getlift/update-cdk-to-v2
Browse files Browse the repository at this point in the history
Update CDK to v2
  • Loading branch information
fredericbarthelet committed Apr 28, 2022
2 parents d2a8fa7 + 995c6e4 commit 7b1a3f7
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 78 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ jobs:
strategy:
matrix:
node:
- "12.13.0"
- 14
- 16
- 17
- 18
serverless:
- "2.36.0"
- "2"
Expand Down
21 changes: 4 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,13 @@
"repository": "https://github.com/getlift/lift",
"description": "Lift",
"dependencies": {
"@aws-cdk/aws-apigatewayv2": "^1.138",
"@aws-cdk/aws-apigatewayv2-integrations": "^1.138",
"@aws-cdk/aws-certificatemanager": "^1.138",
"@aws-cdk/aws-cloudfront": "^1.138",
"@aws-cdk/aws-cloudfront-origins": "^1.138",
"@aws-cdk/aws-cloudwatch": "^1.138",
"@aws-cdk/aws-dynamodb": "^1.138",
"@aws-cdk/aws-ec2": "^1.138",
"@aws-cdk/aws-events": "^1.138",
"@aws-cdk/aws-iam": "^1.138",
"@aws-cdk/aws-kms": "^1.138",
"@aws-cdk/aws-lambda": "^1.138",
"@aws-cdk/aws-s3": "^1.138",
"@aws-cdk/aws-sns": "^1.138",
"@aws-cdk/aws-sqs": "^1.138",
"@aws-cdk/core": "^1.138",
"@aws-cdk/aws-apigatewayv2-alpha": "^2.21.1-alpha.0",
"aws-cdk-lib": "^2.21.1",
"aws-sdk": "^2.942.0",
"chalk": "^4.1.1",
"change-case": "^4.1.2",
"cidr-split": "^0.1.2",
"constructs": "^10.0.127",
"inquirer": "^7.3.3",
"js-yaml": "^3.14.1",
"lodash": "^4.17.21",
Expand Down Expand Up @@ -67,7 +54,7 @@
"typescript": "^4.3.4"
},
"engines": {
"node": ">=12.13 <18"
"node": ">=14.15.0 <19"
},
"files": [
"/dist"
Expand Down
4 changes: 2 additions & 2 deletions src/CloudFormation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DescribeStacksInput, DescribeStacksOutput } from "aws-sdk/clients/cloudformation";
import type { CfnOutput } from "@aws-cdk/core";
import { Stack } from "@aws-cdk/core";
import type { CfnOutput } from "aws-cdk-lib";
import { Stack } from "aws-cdk-lib";
import type { AwsProvider } from "@lift/providers";
import { getUtils } from "./utils/logger";

Expand Down
2 changes: 1 addition & 1 deletion src/constructs/abstracts/AwsConstruct.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Construct as CdkConstruct } from "@aws-cdk/core";
import { Construct as CdkConstruct } from "constructs";
import type { AwsProvider } from "@lift/providers";
import type { ConstructInterface } from "@lift/constructs";

Expand Down
6 changes: 3 additions & 3 deletions src/constructs/aws/DatabaseDynamoDBSingleTable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Construct as CdkConstruct } from "@aws-cdk/core";
import { CfnOutput, Fn, Stack } from "@aws-cdk/core";
import { AttributeType, BillingMode, StreamViewType, Table } from "@aws-cdk/aws-dynamodb";
import type { Construct as CdkConstruct } from "constructs";
import { CfnOutput, Fn, Stack } from "aws-cdk-lib";
import { AttributeType, BillingMode, StreamViewType, Table } from "aws-cdk-lib/aws-dynamodb";
import type { FromSchema } from "json-schema-to-ts";
import type { AwsProvider } from "@lift/providers";
import { AwsConstruct } from "@lift/constructs/abstracts";
Expand Down
16 changes: 8 additions & 8 deletions src/constructs/aws/Queue.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Key } from "@aws-cdk/aws-kms";
import { Queue as CdkQueue, QueueEncryption } from "@aws-cdk/aws-sqs";
import { Key } from "aws-cdk-lib/aws-kms";
import { Queue as CdkQueue, QueueEncryption } from "aws-cdk-lib/aws-sqs";
import type { FromSchema } from "json-schema-to-ts";
import { Alarm, ComparisonOperator, Metric } from "@aws-cdk/aws-cloudwatch";
import { Subscription, SubscriptionProtocol, Topic } from "@aws-cdk/aws-sns";
import type { AlarmActionConfig } from "@aws-cdk/aws-cloudwatch/lib/alarm-action";
import type { Construct as CdkConstruct } from "@aws-cdk/core";
import { CfnOutput, Duration } from "@aws-cdk/core";
import { Alarm, ComparisonOperator, Metric } from "aws-cdk-lib/aws-cloudwatch";
import { Subscription, SubscriptionProtocol, Topic } from "aws-cdk-lib/aws-sns";
import type { AlarmActionConfig } from "aws-cdk-lib/aws-cloudwatch/lib/alarm-action";
import type { Construct as CdkConstruct } from "constructs";
import { CfnOutput, Duration } from "aws-cdk-lib";
import chalk from "chalk";
import type { PurgeQueueRequest, SendMessageRequest } from "aws-sdk/clients/sqs";
import { isNil } from "lodash";
Expand Down Expand Up @@ -221,7 +221,7 @@ export class Queue extends AwsConstruct {
metric: new Metric({
namespace: "AWS/SQS",
metricName: "ApproximateNumberOfMessagesVisible",
dimensions: {
dimensionsMap: {
QueueName: dlq.queueName,
},
statistic: "Sum",
Expand Down
16 changes: 8 additions & 8 deletions src/constructs/aws/ServerSideWebsite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bucket } from "@aws-cdk/aws-s3";
import { Bucket } from "aws-cdk-lib/aws-s3";
import {
AllowedMethods,
CacheHeaderBehavior,
Expand All @@ -12,17 +12,17 @@ import {
OriginRequestPolicy,
OriginRequestQueryStringBehavior,
ViewerProtocolPolicy,
} from "@aws-cdk/aws-cloudfront";
import type { Construct } from "@aws-cdk/core";
import { CfnOutput, Duration, Fn, RemovalPolicy } from "@aws-cdk/core";
} from "aws-cdk-lib/aws-cloudfront";
import type { Construct } from "constructs";
import { CfnOutput, Duration, Fn, RemovalPolicy } from "aws-cdk-lib";
import type { FromSchema } from "json-schema-to-ts";
import { HttpOrigin, S3Origin } from "@aws-cdk/aws-cloudfront-origins";
import * as acm from "@aws-cdk/aws-certificatemanager";
import type { BehaviorOptions, ErrorResponse } from "@aws-cdk/aws-cloudfront/lib/distribution";
import { HttpOrigin, S3Origin } from "aws-cdk-lib/aws-cloudfront-origins";
import * as acm from "aws-cdk-lib/aws-certificatemanager";
import type { BehaviorOptions, ErrorResponse } from "aws-cdk-lib/aws-cloudfront/lib/distribution";
import * as path from "path";
import * as fs from "fs";
import { flatten } from "lodash";
import * as cloudfront from "@aws-cdk/aws-cloudfront";
import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
import { AwsConstruct } from "@lift/constructs/abstracts";
import type { ConstructCommands } from "@lift/constructs";
import type { AwsProvider } from "@lift/providers";
Expand Down
6 changes: 3 additions & 3 deletions src/constructs/aws/SinglePageApp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as cloudfront from "@aws-cdk/aws-cloudfront";
import { FunctionEventType } from "@aws-cdk/aws-cloudfront";
import type { Construct as CdkConstruct } from "@aws-cdk/core";
import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
import { FunctionEventType } from "aws-cdk-lib/aws-cloudfront";
import type { Construct as CdkConstruct } from "constructs";
import type { AwsProvider } from "@lift/providers";
import { redirectToMainDomain } from "../../classes/cloudfrontFunctions";
import { getCfnFunctionAssociations } from "../../utils/getDefaultCfnFunctionAssociations";
Expand Down
6 changes: 3 additions & 3 deletions src/constructs/aws/StaticWebsite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as cloudfront from "@aws-cdk/aws-cloudfront";
import { FunctionEventType } from "@aws-cdk/aws-cloudfront";
import type { Construct as CdkConstruct } from "@aws-cdk/core";
import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
import { FunctionEventType } from "aws-cdk-lib/aws-cloudfront";
import type { Construct as CdkConstruct } from "constructs";
import type { AwsProvider } from "@lift/providers";
import { redirectToMainDomain } from "../../classes/cloudfrontFunctions";
import { getCfnFunctionAssociations } from "../../utils/getDefaultCfnFunctionAssociations";
Expand Down
6 changes: 3 additions & 3 deletions src/constructs/aws/Storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BlockPublicAccess, Bucket, BucketEncryption, StorageClass } from "@aws-cdk/aws-s3";
import type { Construct as CdkConstruct } from "@aws-cdk/core";
import { CfnOutput, Duration, Fn, Stack } from "@aws-cdk/core";
import { BlockPublicAccess, Bucket, BucketEncryption, StorageClass } from "aws-cdk-lib/aws-s3";
import type { Construct as CdkConstruct } from "constructs";
import { CfnOutput, Duration, Fn, Stack } from "aws-cdk-lib";
import type { FromSchema } from "json-schema-to-ts";
import type { AwsProvider } from "@lift/providers";
import { AwsConstruct } from "@lift/constructs/abstracts";
Expand Down
6 changes: 3 additions & 3 deletions src/constructs/aws/Vpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Vpc as CdkVpc, Peer, Port, SecurityGroup } from "@aws-cdk/aws-ec2";
import type { Construct as CdkConstruct } from "@aws-cdk/core";
import { Vpc as CdkVpc, Peer, Port, SecurityGroup } from "aws-cdk-lib/aws-ec2";
import type { Construct as CdkConstruct } from "constructs";
import type { FromSchema } from "json-schema-to-ts";
import type { AwsProvider } from "@lift/providers";
import type { ConstructInterface } from "@lift/constructs";
Expand Down Expand Up @@ -39,7 +39,7 @@ export class Vpc extends CdkVpc implements ConstructInterface {

// Auto-register the VPC
provider.setVpcConfig(
[this.appSecurityGroup.securityGroupName],
[this.appSecurityGroup.securityGroupId],
this.privateSubnets.map((subnet) => subnet.subnetId)
);
}
Expand Down
13 changes: 7 additions & 6 deletions src/constructs/aws/Webhook.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Construct as CdkConstruct } from "@aws-cdk/core";
import { CfnOutput, Fn } from "@aws-cdk/core";
import { CfnAuthorizer, CfnIntegration, CfnRoute, HttpApi } from "@aws-cdk/aws-apigatewayv2";
import { Function } from "@aws-cdk/aws-lambda";
import { EventBus } from "@aws-cdk/aws-events";
import type { Construct as CdkConstruct } from "constructs";
import { CfnOutput, Fn } from "aws-cdk-lib";
import { CfnAuthorizer, CfnIntegration, CfnRoute } from "aws-cdk-lib/aws-apigatewayv2";
import { HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
import { Function } from "aws-cdk-lib/aws-lambda";
import { EventBus } from "aws-cdk-lib/aws-events";
import type { FromSchema } from "json-schema-to-ts";
import { PolicyDocument, PolicyStatement, Role, ServicePrincipal } from "@aws-cdk/aws-iam";
import { PolicyDocument, PolicyStatement, Role, ServicePrincipal } from "aws-cdk-lib/aws-iam";
import type { AwsProvider } from "@lift/providers";
import { AwsConstruct } from "@lift/constructs/abstracts";
import ServerlessError from "../../utils/error";
Expand Down
18 changes: 9 additions & 9 deletions src/constructs/aws/abstracts/StaticWebsiteAbstract.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as acm from "@aws-cdk/aws-certificatemanager";
import * as cloudfront from "@aws-cdk/aws-cloudfront";
import type { ErrorResponse } from "@aws-cdk/aws-cloudfront";
import * as acm from "aws-cdk-lib/aws-certificatemanager";
import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
import type { ErrorResponse } from "aws-cdk-lib/aws-cloudfront";
import {
AllowedMethods,
CachePolicy,
Distribution,
FunctionEventType,
HttpVersion,
ViewerProtocolPolicy,
} from "@aws-cdk/aws-cloudfront";
import { S3Origin } from "@aws-cdk/aws-cloudfront-origins";
import { Bucket } from "@aws-cdk/aws-s3";
import type { Construct as CdkConstruct } from "@aws-cdk/core";
import { Duration } from "@aws-cdk/core";
import { CfnOutput, RemovalPolicy } from "@aws-cdk/core";
} from "aws-cdk-lib/aws-cloudfront";
import { S3Origin } from "aws-cdk-lib/aws-cloudfront-origins";
import { Bucket } from "aws-cdk-lib/aws-s3";
import type { Construct as CdkConstruct } from "constructs";
import { Duration } from "aws-cdk-lib";
import { CfnOutput, RemovalPolicy } from "aws-cdk-lib";
import type { ConstructCommands } from "@lift/constructs";
import { AwsConstruct } from "@lift/constructs/abstracts";
import type { AwsProvider } from "@lift/providers";
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { AwsIamPolicyStatements } from "@serverless/typescript";
import * as path from "path";
import { readFileSync } from "fs";
import { dump } from "js-yaml";
import { DefaultTokenResolver, Lazy, StringConcat, Tokenization } from "@aws-cdk/core";
import { DefaultTokenResolver, Lazy, StringConcat, Tokenization } from "aws-cdk-lib";
import type { FromSchema } from "json-schema-to-ts";
import type { ProviderInterface, StaticProviderInterface } from "@lift/providers";
import { AwsProvider, StripeProvider } from "@lift/providers";
Expand Down
10 changes: 7 additions & 3 deletions src/providers/AwsProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CfnOutput } from "@aws-cdk/core";
import { App, Stack } from "@aws-cdk/core";
import type { CfnOutput } from "aws-cdk-lib";
import { App, DefaultStackSynthesizer, Stack } from "aws-cdk-lib";
import { get, merge } from "lodash";
import type { AwsCfInstruction, AwsLambdaVpcConfig } from "@serverless/typescript";
import type { ProviderInterface } from "@lift/providers";
Expand Down Expand Up @@ -69,7 +69,11 @@ export class AwsProvider implements ProviderInterface {
constructor(private readonly serverless: Serverless) {
this.stackName = serverless.getProvider("aws").naming.getStackName();
this.app = new App();
this.stack = new Stack(this.app);
this.stack = new Stack(this.app, undefined, {
synthesizer: new DefaultStackSynthesizer({
generateBootstrapVersionRule: false,
}),
});
this.legacyProvider = serverless.getProvider("aws");
this.naming = this.legacyProvider.naming;
this.region = serverless.getProvider("aws").getRegion();
Expand Down
2 changes: 1 addition & 1 deletion src/types/serverless.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AWS } from "@serverless/typescript";
import type { Stack } from "@aws-cdk/core";
import type { Stack } from "aws-cdk-lib";

export type Hook = () => void | Promise<void>;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/getDefaultCfnFunctionAssociations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CfnDistribution } from "@aws-cdk/aws-cloudfront";
import type { CfnDistribution } from "aws-cdk-lib/aws-cloudfront";

interface CfnFunctionAssociation {
EventType: string;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/serverSideWebsite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ describe("server-side website", () => {
ViewerCertificate: {
AcmCertificateArn:
"arn:aws:acm:us-east-1:123456615250:certificate/0a28e63d-d3a9-4578-9f8b-14347bfe8123",
MinimumProtocolVersion: "TLSv1.2_2019",
MinimumProtocolVersion: "TLSv1.2_2021",
SslSupportMethod: "sni-only",
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/unit/staticWebsites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe("static websites", () => {
ViewerCertificate: {
AcmCertificateArn:
"arn:aws:acm:us-east-1:123456615250:certificate/0a28e63d-d3a9-4578-9f8b-14347bfe8123",
MinimumProtocolVersion: "TLSv1.2_2019",
MinimumProtocolVersion: "TLSv1.2_2021",
SslSupportMethod: "sni-only",
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/unit/vpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("vpc", () => {
>;
expect(vpcConfig).toHaveProperty("SecurityGroupIds");
expect((vpcConfig.SecurityGroupIds as AwsCfInstruction[])[0]).toMatchObject({
Ref: computeLogicalId("vpc", "AppSecurityGroup"),
"Fn::GetAtt": [computeLogicalId("vpc", "AppSecurityGroup"), "GroupId"],
});
expect(vpcConfig).toHaveProperty("SubnetIds");
expect(vpcConfig.SubnetIds).toContainEqual({
Expand Down
2 changes: 1 addition & 1 deletion test/utils/runServerless.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import { Names } from "@aws-cdk/core";
import { Names } from "aws-cdk-lib";
import type originalRunServerless from "@serverless/test/run-serverless";
import setupRunServerlessFixturesEngine from "@serverless/test/setup-run-serverless-fixtures-engine";
import type { AWS } from "@serverless/typescript";
Expand Down

0 comments on commit 7b1a3f7

Please sign in to comment.