Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-apigateway: Custom log format account ID gets translated incorrectly #21731

Closed
LiMuBei opened this issue Aug 24, 2022 · 2 comments · Fixed by #21989
Closed

aws-apigateway: Custom log format account ID gets translated incorrectly #21731

LiMuBei opened this issue Aug 24, 2022 · 2 comments · Fixed by #21989
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1 package/tools Related to AWS CDK Tools or CLI

Comments

@LiMuBei
Copy link

LiMuBei commented Aug 24, 2022

Describe the bug

I want to set up custom log format for API Gateway:

new RestApi(this, "myapi", {
  deployOptions: {
    accessLogFormat: AccessLogFormat.custom(JSON.stringify({
      accountId: AccessLogField.contextAccountId(),
      ...
    })
  })

Expected Behavior

According to the definition of AccessLogField.contextAccountId() this should return The API owner's AWS account ID. After synthesizing the template, this should then get translated to $context.accountId.

Current Behavior

AccessLogField.contextAccountId() gets translated to $context.identity.accountId which would return the account ID of the caller.

Reproduction Steps

Setup a RestApi with custom log format and use AccessLogField.contextAccountId().

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.38.1 (build a5ced21)

Framework Version

No response

Node.js Version

v16.17.0

OS

macOS

Language

Typescript

Language Version

No response

Other information

No response

@LiMuBei LiMuBei added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 24, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Aug 24, 2022
@LiMuBei LiMuBei changed the title (module name): (short issue description) aws-apigateway: Custom log format account ID gets translated incorrectly Aug 24, 2022
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Aug 24, 2022
@rix0rrr rix0rrr added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1 and removed needs-triage This issue or PR still needs to be triaged. labels Sep 2, 2022
@rix0rrr rix0rrr removed their assignment Sep 2, 2022
@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 2, 2022

That's a documentation mistake.

I would recommend deprecating the current method, and adding contextCallerAccountId() and contextOwnerAccountId() to avoid the confusion in the future.

@mergify mergify bot closed this as completed in #21989 Sep 14, 2022
mergify bot pushed a commit that referenced this issue Sep 14, 2022
Closes: #21731  

As mentioned in the referenced PR the `contextAccountId` doc string contained the wrong docstring as it in fact returns the 
callers account id.

Implemented a the fix as per the ticket recommendation.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants