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

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

Closed
1 of 2 tasks
tmokmss opened this issue Apr 22, 2024 · 5 comments · Fixed by #30061 or codu-code/codu#969 · May be fixed by NOUIY/aws-solutions-constructs#112, codu-code/codu#987 or gitafolabi/kreuzlaker#2
Labels
@aws-cdk/aws-stepfunctions-tasks effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@tmokmss
Copy link
Contributor

tmokmss commented Apr 22, 2024

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

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.138.0

Environment details (OS name and version, etc.)

n/a

@tmokmss tmokmss added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Apr 22, 2024
@pahud
Copy link
Contributor

pahud commented Apr 22, 2024

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

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Apr 22, 2024
@Zeromika
Copy link

Zeromika commented May 9, 2024

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
Copy link
Contributor Author

tmokmss commented May 21, 2024

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.

@mergify mergify bot closed this as completed in #30061 Jun 24, 2024
mergify bot pushed a commit that referenced this issue Jun 24, 2024
…PI call (#30061)

### Issue # (if applicable)

Closes #29918.

### Reason for this change

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.

Our usecase is to automate a cross-region failover scenario 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.

### Description of changes

This PR adds a new construct `CallAwsServiceCrossRegion` that deploys 1. a Lambda function to call AWS API in different regions 2. SFn task to call the function.

Because most properties are compatible with the existing `CallAwsService` construct, you can use the new construct by just adding the `region` property.

Additionally, it also allows to set `endpoint` to override AWS API endpoint, because some AWS APIs requires you to override it. (e.g. [Route53 ARC](https://docs.aws.amazon.com/r53recovery/latest/dg/getting-started-cli-routing.control-state.html))

### Description of how you validated changes

Added unit tests and integ tests.

### Checklist
- [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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.

@aws-cdk-automation
Copy link
Collaborator

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.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.