Skip to content

Commit d04e40f

Browse files
authored
feat(apigatewayv2): HttpStage access logging (#33977)
### Issue # (if applicable) Closes #11100 ### Description of changes - apigwv2 HttpStage support access logging to CloudWatch Logs https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-logging.html - Same logic as V1 without Firehose as not supported. ### Description of how you validated changes Unit + Integ ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c993d34 commit d04e40f

16 files changed

+480
-134
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.stage.js.snapshot/aws-cdk-aws-apigatewayv2-http-stage.assets.json

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.stage.js.snapshot/aws-cdk-aws-apigatewayv2-http-stage.template.json

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
22
"Resources": {
3+
"MyLogGroup5C0DAD85": {
4+
"Type": "AWS::Logs::LogGroup",
5+
"Properties": {
6+
"RetentionInDays": 731
7+
},
8+
"UpdateReplacePolicy": "Retain",
9+
"DeletionPolicy": "Retain"
10+
},
311
"HttpApiF5A9A8A7": {
412
"Type": "AWS::ApiGatewayV2::Api",
513
"Properties": {
@@ -10,6 +18,15 @@
1018
"HttpStageWithPropertiesC0AABA83": {
1119
"Type": "AWS::ApiGatewayV2::Stage",
1220
"Properties": {
21+
"AccessLogSettings": {
22+
"DestinationArn": {
23+
"Fn::GetAtt": [
24+
"MyLogGroup5C0DAD85",
25+
"Arn"
26+
]
27+
},
28+
"Format": "{\"extendedRequestId\":\"$context.extendedRequestId\",\"requestTime\":\"$context.requestTime\"}"
29+
},
1330
"ApiId": {
1431
"Ref": "HttpApiF5A9A8A7"
1532
},

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.stage.js.snapshot/awscdkawsapigatewayv2httpstagetestDefaultTestDeployAssert66182A52.assets.json

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.stage.js.snapshot/awscdkawsapigatewayv2httpstagetestDefaultTestDeployAssert66182A52.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.stage.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.stage.js.snapshot/integ.json

+5-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.stage.js.snapshot/manifest.json

+64-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.stage.js.snapshot/tree.json

+1-111
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
#!/usr/bin/env node
2+
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
23
import * as cdk from 'aws-cdk-lib';
3-
import * as apigw from 'aws-cdk-lib/aws-apigatewayv2';
4+
import * as apigwv2 from 'aws-cdk-lib/aws-apigatewayv2';
5+
import * as apigw from 'aws-cdk-lib/aws-apigateway';
6+
import * as logs from 'aws-cdk-lib/aws-logs';
47

58
const app = new cdk.App();
69
const stack = new cdk.Stack(app, 'aws-cdk-aws-apigatewayv2-http-stage');
710

8-
const httpApi = new apigw.HttpApi(stack, 'HttpApi', { createDefaultStage: false });
9-
new apigw.HttpStage(stack, 'HttpStageWithProperties', {
11+
const testLogGroup = new logs.LogGroup(stack, 'MyLogGroup');
12+
13+
const httpApi = new apigwv2.HttpApi(stack, 'HttpApi', { createDefaultStage: false });
14+
new apigwv2.HttpStage(stack, 'HttpStageWithProperties', {
1015
httpApi,
1116
throttle: {
1217
rateLimit: 1000,
1318
burstLimit: 1000,
1419
},
1520
detailedMetricsEnabled: true,
1621
description: 'My Stage',
22+
accessLogSettings: {
23+
destination: new apigwv2.LogGroupLogDestination(testLogGroup),
24+
format: apigw.AccessLogFormat.custom(JSON.stringify({
25+
extendedRequestId: apigw.AccessLogField.contextExtendedRequestId(),
26+
requestTime: apigw.AccessLogField.contextRequestTime(),
27+
})),
28+
},
1729
});
1830

19-
app.synth();
31+
new IntegTest(app, 'aws-cdk-aws-apigatewayv2-http-stage-test', {
32+
testCases: [stack],
33+
});

0 commit comments

Comments
 (0)