aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.58k stars 3.88k forks source link

stepfunctions-tasks: Step Functions task for cross-region AWS API call #29918

Closed tmokmss closed 3 months ago

tmokmss commented 5 months ago

Describe the feature

It would be useful if we could call AWS API across regions from a Step Functions state machine.

Currently it is not officially supported even with AWS SDK integration tasks.

Currently, cross-Region AWS SDK integration and cross-Region AWS resource access aren't available in Step Functions. https://docs.aws.amazon.com/step-functions/latest/dg/concepts-access-cross-acct-resources.html

Use Case

My usecase is to automate cross-region failover in a multi-region application. This requires you to orchestrate multiple API calls for both active and standby regions (e.g. failover Aurora DB cluster, rewrite AppConfig parameter, etc), and it would be great if we can manage these operations in a single state machine.

Proposed Solution

Add a construct like CallAwsServiceAcrossRegion in the aws-stepfunctions-tasks module. The API would be similar to the existing CallAwsService task, with an additional property region.

In the new construct, we create a Lambda function to proxy the API request to the target region, use LambdaInvoke task internally, and call AWS API from the function.

I wrote an example Lambda function to proxy AWS API requests: https://gist.github.com/tmokmss/aeb85fc8c3076cbc5d9ae1c6698969d1

The alternative option would be adding a property like region to CallAwsService task, but it could potentially make a breaking change when SFn would officially start to support cross-region AWS API call. That is why I think the above approach (creating a brand new construct) is better.

Other Information

No response

Acknowledgements

CDK version used

2.138.0

Environment details (OS name and version, etc.)

n/a

pahud commented 5 months ago

Awesome! Love this idea. Thank you @tmokmss !!

Zeromika commented 5 months ago

Would love to use this feature soon! We were having to write custom lambdas to take care of the calls but this would be pretty useful if it comes out of the box.

tmokmss commented 4 months ago

This can also be useful to call Bedrock client API (InvokeModel), because currently the supported regions are limited (even only us-west-2 for Claude Opus) and often requires cross-region API call.

github-actions[bot] commented 3 months ago

⚠️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.

aws-cdk-automation commented 2 months ago

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.