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

chore(scheduler-targets-alpha): imported function as a LambdaInvoke target results in synth-time error #29615

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

anan-k
Copy link

@anan-k anan-k commented Mar 26, 2024

Issue # (if applicable)

Closes #29284

Reason for this change

When a lambda function in another stack is imported by ARN and used as a LambdaInvoke target, a synth-time error occurred due to an issue with environment (account or region) validation sameEnvDimension. The validation compares two environment values such as account or region and returns true/false. The validation passes only if the values are the same (SAME) or both are unresolved (BOTH_UNRESOLVED), but since the region of the imported function was unresolved, it resulted in ONE_UNRESOLVED, causing the error. To resolve this, I modified the validation to allow the ONE_UNRESOLVED case.

The proposed solution in the issue was to skip validations if sameEnvironment is set to true on the imported lambda. However, I did not adopt this solution because the sameEnvironment attribute is not stored in the Lambda function itself and cannot be used to toggle the validation.

Description of changes

I changed the sameEnvDimension function to allow the case where either one of the parameters is unresolved.
I made these changes based on the implementation in aws-cdk-lib/aws-events-targets/lib/util.ts

Description of how you validated changes

I added a unit test for the LambdaInvoke target to cover the case when an imported lambda function is used.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Mar 26, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team March 26, 2024 05:30
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@anan-k
Copy link
Author

anan-k commented Mar 26, 2024

Exemption Request: This PR just changes validation behavior and does not affect the integration test. The changes are covered by unit tests.

@aws-cdk-automation aws-cdk-automation added pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/needs-maintainer-review This PR needs a review from a Core Team Member labels Mar 26, 2024
@anan-k anan-k changed the title fix(scheduler-targets-alaha): imported function as a LambdaInvoke target results in synth-time error fix(scheduler-targets-alpha): imported function as a LambdaInvoke target results in synth-time error Mar 27, 2024
This was referenced Apr 1, 2024
Copy link
Contributor

@aaythapa aaythapa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for your contribution! Did a quick review and I'm not sure if this is the best way to fix this, see comment.

The proposed solution in the issue was to skip validations if sameEnvironment is set to true on the imported lambda. However, I did not adopt this solution because the sameEnvironment attribute is not stored in the Lambda function itself and cannot be used to toggle the validation.

Agree, that doesn't work for now. Will do a deeper dive to see if there is a way to expose this property

*/
export function sameEnvDimension(dim1: string, dim2: string) {
return [TokenComparison.SAME, TokenComparison.BOTH_UNRESOLVED].includes(Token.compareStrings(dim1, dim2));
return [TokenComparison.SAME, TokenComparison.ONE_UNRESOLVED, TokenComparison.BOTH_UNRESOLVED].includes(Token.compareStrings(dim1, dim2));
Copy link
Contributor

@aaythapa aaythapa Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong but this essentially negates the need for the validation as, I believe now, all cases will return true.

EDIT: I see that TokenComparison.DIFFERENT can also be returned which would return false for this function. I'm still not sure if this is the best way to go about resolving this issue as it could change more things than just fixing this issue. Will consult with the team

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment: #29615 (comment)

@anan-k
Copy link
Author

anan-k commented Apr 12, 2024

Hi Aayush, thank you for your review and comment. Let me check it.

@anan-k
Copy link
Author

anan-k commented Apr 18, 2024

@aaythapa
I'm sorry for the late reply and thank you again for your comment.

As you mentioned, this change is more of a fundamental solution to just resolve this issue rather than a minimum change. However, the proposed addition of the sameEnvironment property to Lambda is considered to have an even greater impact. Furthermore, due to the nature of the property, it may not be appropriate for Lambda to retain it.

@anan-k anan-k changed the title fix(scheduler-targets-alpha): imported function as a LambdaInvoke target results in synth-time error chore(scheduler-targets-alpha): imported function as a LambdaInvoke target results in synth-time error May 13, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review May 13, 2024 07:11

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 0da03df
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p1 pr/needs-maintainer-review This PR needs a review from a Core Team Member pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-scheduler-targets-alpha): Cannot use imported function ARN with LambdaInvoke target
3 participants