From fa84dbdb8ff3351485470a2914cc8956c13a2f04 Mon Sep 17 00:00:00 2001 From: Marcin Kolny Date: Wed, 20 May 2020 15:31:56 +0100 Subject: [PATCH] fix(apigateway): contextAccountId in AccessLogField incorrectly resolves to requestId ## Commit Message fix(apigateway): contextAccountId in AccessLogField incorrectly resolves to requestId (#7952) fixes #7951 ## End Commit Message ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-apigateway/lib/access-log.ts | 2 +- packages/@aws-cdk/aws-apigateway/test/test.access-log.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/access-log.ts b/packages/@aws-cdk/aws-apigateway/lib/access-log.ts index 09213c1162bfc..b55c6bf24dc9f 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/access-log.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/access-log.ts @@ -46,7 +46,7 @@ export class AccessLogField { * The API owner's AWS account ID. */ public static contextAccountId() { - return '$context.requestId'; + return '$context.identity.accountId'; } /** diff --git a/packages/@aws-cdk/aws-apigateway/test/test.access-log.ts b/packages/@aws-cdk/aws-apigateway/test/test.access-log.ts index 19c035a698b17..cb1098dadd5d3 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.access-log.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.access-log.ts @@ -38,12 +38,13 @@ export = { requestId: apigateway.AccessLogField.contextRequestId(), sourceIp: apigateway.AccessLogField.contextIdentitySourceIp(), method: apigateway.AccessLogField.contextHttpMethod(), + accountId: apigateway.AccessLogField.contextAccountId(), userContext: { sub: apigateway.AccessLogField.contextAuthorizerClaims('sub'), email: apigateway.AccessLogField.contextAuthorizerClaims('email'), }, })); - test.deepEqual(testFormat.toString(), '{"requestId":"$context.requestId","sourceIp":"$context.identity.sourceIp","method":"$context.httpMethod","userContext":{"sub":"$context.authorizer.claims.sub","email":"$context.authorizer.claims.email"}}'); + test.deepEqual(testFormat.toString(), '{"requestId":"$context.requestId","sourceIp":"$context.identity.sourceIp","method":"$context.httpMethod","accountId":"$context.identity.accountId","userContext":{"sub":"$context.authorizer.claims.sub","email":"$context.authorizer.claims.email"}}'); test.done(); },