Skip to content

Commit

Permalink
fix(apigateway): contextAccountId in AccessLogField incorrectly resol…
Browse files Browse the repository at this point in the history
…ves to requestId

## Commit Message
fix(apigateway): contextAccountId in AccessLogField incorrectly resolves to requestId (aws#7952)

fixes aws#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*
  • Loading branch information
loganek authored and karupanerura committed May 21, 2020
1 parent ea48044 commit fa84dbd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/access-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class AccessLogField {
* The API owner's AWS account ID.
*/
public static contextAccountId() {
return '$context.requestId';
return '$context.identity.accountId';
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.access-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down

0 comments on commit fa84dbd

Please sign in to comment.