Skip to content

Commit 85ddd18

Browse files
committed
update dependencies, migrate apigw
1 parent 8529d85 commit 85ddd18

File tree

4 files changed

+785
-656
lines changed

4 files changed

+785
-656
lines changed

cdk/lib/cdk-stack.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import * as cdk from '@aws-cdk/core';
2-
import * as lambda from '@aws-cdk/aws-lambda';
3-
import * as apigateway from '@aws-cdk/aws-apigateway';
4-
import * as cloudfront from '@aws-cdk/aws-cloudfront';
1+
import * as cdk from "@aws-cdk/core";
2+
import * as lambda from "@aws-cdk/aws-lambda";
3+
import * as apigatewayv2 from "@aws-cdk/aws-apigatewayv2";
4+
import * as apigatewayv2Integrations from "@aws-cdk/aws-apigatewayv2-integrations";
5+
import * as cloudfront from "@aws-cdk/aws-cloudfront";
56
import * as path from "path";
67

78
export class CdkStack extends cdk.Stack {
@@ -13,34 +14,43 @@ export class CdkStack extends cdk.Stack {
1314
runtime: lambda.Runtime.NODEJS_12_X,
1415
handler: "build/lambda.handler",
1516
code: lambda.Code.fromAsset(path.join(__dirname, "../../"), {
16-
exclude: ["cdk"]
17-
})
17+
exclude: ["cdk"],
18+
}),
1819
});
1920

20-
// ApiGW
21-
const apigw = new apigateway.LambdaRestApi(this, "MyApi", {
21+
// ApiGWv2
22+
const httpApiIntegration = new apigatewayv2Integrations.LambdaProxyIntegration({
2223
handler: fn,
23-
proxy: true
24+
});
25+
26+
const httpApi = new apigatewayv2.HttpApi(this, "MyApi");
27+
httpApi.addRoutes({
28+
path: "/",
29+
methods: [apigatewayv2.HttpMethod.ANY],
30+
integration: httpApiIntegration,
2431
});
2532

2633
// CF
2734
const feCf = new cloudfront.CloudFrontWebDistribution(this, "MyCf", {
2835
defaultRootObject: "/",
29-
originConfigs: [{
30-
customOriginSource: {
31-
domainName: `${apigw.restApiId}.execute-api.${this.region}.${this.urlSuffix}`,
36+
originConfigs: [
37+
{
38+
customOriginSource: {
39+
domainName: `${httpApi.httpApiId}.execute-api.${this.region}.${this.urlSuffix}`,
40+
},
41+
behaviors: [
42+
{
43+
isDefaultBehavior: true,
44+
},
45+
],
3246
},
33-
originPath: '/' + apigw.deploymentStage.stageName,
34-
behaviors: [{
35-
isDefaultBehavior: true,
36-
}]
37-
}],
47+
],
3848
enableIpV6: true,
3949
});
4050

4151
// Output
4252
new cdk.CfnOutput(this, "myOut", {
43-
value: feCf.domainName
53+
value: feCf.distributionDomainName,
4454
});
4555
}
4656
}

cdk/package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@
1111
"cdk": "cdk"
1212
},
1313
"devDependencies": {
14-
"@aws-cdk/assert": "1.32.2",
14+
"@aws-cdk/assert": "1.74.0",
1515
"@types/jest": "^24.0.22",
16-
"@types/node": "10.17.5",
17-
"aws-cdk": "1.32.2",
16+
"@types/node": "14.14.9",
17+
"aws-cdk": "1.74.0",
1818
"jest": "^24.9.0",
1919
"ts-jest": "^24.1.0",
20-
"ts-node": "^8.1.0",
21-
"typescript": "~3.7.2"
20+
"ts-node": "^9.0.0",
21+
"typescript": "~4.1.2"
2222
},
2323
"dependencies": {
24-
"@aws-cdk/aws-apigateway": "^1.32.2",
25-
"@aws-cdk/aws-cloudfront": "^1.32.2",
26-
"@aws-cdk/aws-lambda": "^1.32.2",
27-
"@aws-cdk/core": "1.32.2",
24+
"@aws-cdk/aws-apigatewayv2": "^1.74.0",
25+
"@aws-cdk/aws-apigatewayv2-integrations": "^1.74.0",
26+
"@aws-cdk/aws-cloudfront": "^1.74.0",
27+
"@aws-cdk/aws-lambda": "^1.74.0",
28+
"@aws-cdk/core": "1.74.0",
2829
"source-map-support": "^0.5.16"
2930
}
30-
}
31+
}

0 commit comments

Comments
 (0)