Skip to content

Conversation

@t3yamoto
Copy link

@t3yamoto t3yamoto commented Sep 12, 2025

Issue # (if applicable)

Closes #35317.

Reason for this change

When using CallAwsServiceCrossRegion with the credentials property for cross-account scenarios, the StateMachine execution role assumes the specified credentials role and attempts to execute the auto-generated
Lambda function with that role. This causes Lambda execution failures because the cross-account role lacks lambda:InvokeFunction permissions for the Lambda function in the original account.

Description of changes

Added a new awsSdkCredentials property to CallAwsServiceCrossRegion that allows specifying IAM credentials exclusively for AWS SDK calls within the Lambda function, without affecting Lambda execution itself.

Key changes:

  • Added awsSdkCredentials property to CallAwsServiceCrossRegionOptions interface
  • Modified Lambda handler to accept assumeRoleArn parameter and use STS AssumeRole for AWS SDK client initialization
  • Added automatic sts:AssumeRole IAM permission when awsSdkCredentials is specified
  • Lambda function continues to execute with its normal execution role while AWS SDK calls use the assumed role

Design decisions:

  • Chose non-breaking approach (Option 2 from issue discussion) by adding new property instead of modifying existing credentials behavior
  • Used STS AssumeRole within Lambda handler rather than at Step Functions level to maintain proper separation of concerns
  • Added dependency on @aws-sdk/client-sts for assume role functionality

Describe any new or updated permissions being added

When awsSdkCredentials is specified, the Lambda execution role automatically receives:

  • sts:AssumeRole permission on all resources (*) to assume the specified cross-account role

Description of how you validated changes

  • Added comprehensive integration test (integ.call-aws-service-cross-region-cross-account.ts) that validates cross-account and cross-region DynamoDB API calls
  • Added unit tests for the Lambda handler's assume role functionality
  • Integration test creates resources in two different accounts and regions to simulate real-world cross-account scenarios

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 the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Sep 12, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team September 12, 2025 13:52
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Sep 12, 2025
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.

(This review is outdated)

@t3yamoto t3yamoto changed the title feat(aws-stepfunctions-tasks): add AWS SDK credentials support to CallAwsServiceCrossRegion feat(stepfunctions-tasks): add AWS SDK credentials support to CallAwsServiceCrossRegion Sep 12, 2025
@t3yamoto t3yamoto force-pushed the add-aws-sdk-credentials branch from 79472e3 to a1e4f8f Compare September 16, 2025 08:43
@t3yamoto t3yamoto force-pushed the add-aws-sdk-credentials branch from a1e4f8f to eac302a Compare September 16, 2025 10:08
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 16, 2025 14:00

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

@t3yamoto t3yamoto marked this pull request as ready for review September 16, 2025 14:21
@t3yamoto t3yamoto changed the title feat(stepfunctions-tasks): add AWS SDK credentials support to CallAwsServiceCrossRegion feat(stepfunctions-tasks): add awsSdkCredentials to CallAwsServiceCrossRegion for cross-account scenarios Sep 17, 2025
@t3yamoto t3yamoto marked this pull request as draft September 18, 2025 00:25
@t3yamoto t3yamoto marked this pull request as ready for review September 18, 2025 15:08
Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Thank you for your contributions! I'm not sure this is the right solution here. Adding this field makes this a leaky abstraction. The end user shouldn't have to know or care that a lambda is being used under the hood. I think that the solution here needs to be purely under the hood.

Please correct me if my understanding of this issue isn't quite correct but it seems that the state machine shouldn't have access to the credentials at all (except to pass them on) and that we're giving it permissions it should not have. That's concerning aside from the problem that the construct simply isn't working for your use case.

Fixing this may be a breaking change but I do think we need to correct where the credentials are going so we're not giving unintended permissions.

Comment on lines +35 to +36
const account = process.env.CDK_INTEG_ACCOUNT || '123456789012';
const crossAccount = process.env.CDK_INTEG_CROSS_ACCOUNT || '234567890123';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please remove the fake account numbers here? I know it's obvious to any human reading this that these are dummy values but having a fallback fake account can sometimes cause issues both with security scanning and with running tests when running the whole suite (and therefore not actually reading the code)

@t3yamoto
Copy link
Author

@TheRealAmazonKendra Thank you for the review and feedback!

I implemented the current approach with the awsSdkCredentials property to avoid breaking changes, but you make a valid point that modifying the behavior of the existing credentials property might be the more appropriate solution.

Regarding "users shouldn't need to know that Lambda is used under the hood" - I agree with this principle in general. However, in cases where users need to minimize trust policies, they might need to understand the internal architecture to properly configure cross-account role trust relationships. The Lambda execution role would need to be trusted by the cross-account role for the assume role operation to succeed.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. Note that PRs with failing linting check or builds are not reviewed, please ensure your build is passing

To prevent automatic closure:

  • Resume work on the PR
  • OR request an exemption by adding a comment containing 'Exemption Request' with justification e.x "Exemption Request: "
  • OR request clarification by adding a comment containing 'Clarification Request' with a question e.x "Clarification Request: "

This PR will automatically close in 14 days if no action is taken.

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review October 23, 2025 13:15

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Nov 17, 2025
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 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aws-stepfunctions-tasks: CallAwsServiceCrossRegion credentials property does not work as expected for cross-account scenarios

3 participants