-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
feat(stepfunctions-tasks): allow region override in call-rest-api task #33252
Conversation
There was a problem hiding this 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)
Clarification Request: This change seems small enough that a README.md update and an integration test update seem a little excessive. Could this PR be reclassified as a fix instead of a feat? Or does a change this small still require a README.md update and an integration test update? |
Just pushed a new commit adding the README.md update, the integration test (with snapshot), and fixing a unit test linting issue (double empty lines) that led to the CodeBuild failure. Apologies, out of habit I ran |
3rd commit out -- didn't actually integration test properly in the 2nd commit. Let me know if I need to squash commits and then force push the combined commit to my dev branch or anything like that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍 Left comments for small docs/test adjustments
* AWS region, e.g. 'us-east-1', where the API is deployed. Uses the region of the Stack | ||
* containing `api`if no region is provided. | ||
* @default the region of the Stack of the `api` in these props |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* AWS region, e.g. 'us-east-1', where the API is deployed. Uses the region of the Stack | |
* containing `api`if no region is provided. | |
* @default the region of the Stack of the `api` in these props | |
* Specify a custom Region where the API is deployed, e.g. 'us-east-1'. | |
* | |
* @default - Uses the Region of the stack containing the `api`. |
the stack in which the provided `api` is created. Passing in a `region` string, | ||
such as `us-west-2`, will instead construct the endpoint with the given region: | ||
|
||
```ts | ||
import * as apigateway from 'aws-cdk-lib/aws-apigateway'; | ||
const restApi = new apigateway.RestApi(this, 'MyRestApi'); | ||
const endpointRegion = 'us-west-2'; | ||
|
||
const invokeTask = new tasks.CallApiGatewayRestApiEndpoint(this, 'Call REST API', { | ||
api: restApi, | ||
stageName: 'prod', | ||
method: tasks.HttpMethod.GET, | ||
region: endpointRegion, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the stack in which the provided `api` is created. Passing in a `region` string, | |
such as `us-west-2`, will instead construct the endpoint with the given region: | |
```ts | |
import * as apigateway from 'aws-cdk-lib/aws-apigateway'; | |
const restApi = new apigateway.RestApi(this, 'MyRestApi'); | |
const endpointRegion = 'us-west-2'; | |
const invokeTask = new tasks.CallApiGatewayRestApiEndpoint(this, 'Call REST API', { | |
api: restApi, | |
stageName: 'prod', | |
method: tasks.HttpMethod.GET, | |
region: endpointRegion, | |
}); | |
the stack in which the provided `api` is created. | |
To construct the endpoint with a different region, use the `region` parameter: | |
```ts | |
import * as apigateway from 'aws-cdk-lib/aws-apigateway'; | |
const restApi = new apigateway.RestApi(this, 'MyRestApi'); | |
const invokeTask = new tasks.CallApiGatewayRestApiEndpoint(this, 'Call REST API', { | |
api: restApi, | |
stageName: 'prod', | |
method: tasks.HttpMethod.GET, | |
region: 'us-west-2', | |
}); |
restApi.root.addMethod('ANY', hello); | ||
|
||
const importedRestApi = apigateway.RestApi.fromRestApiId(sfnStack, 'CrossStackReferenceToApi', restApi.restApiId); | ||
const callEndpointJob = new CallApiGatewayRestApiEndpoint(sfnStack, 'Call APIGW', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please specify another endpoint job using the custom region
parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch... I didn't realize the integ test could succeed without the parameter. Does running yarn integ
only test whether it's a valid snapshot? The SFN execution itself should have failed, but I wasn't sure how to check that. Either way, should have a commit out soon with the custom region
parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
Hi @huoandre thanks for opening this PR. We have this construct that will help with cross region api calls. It does use a custom resources and provides props to configure IAM permissions, override API endpoints etc. Wondering if this PR will replace that construct? Or customers can use that construct instead of the prop introduced in this PR. |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Discuss with Aayush offline, and I think we can have this PR since the custom resource he mentioned is for generic AWS service API calls while this is adding a functionality to an existing call specifically for APIGateway. |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
This pull request has been removed from the queue for the following reason: The pull request can't be updated You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. If you want to requeue this pull request, you need to post a comment with the text: |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #33252 +/- ##
=======================================
Coverage 81.00% 81.00%
=======================================
Files 238 238
Lines 14271 14271
Branches 2492 2492
=======================================
Hits 11560 11560
Misses 2425 2425
Partials 286 286
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@mergify requeue |
✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically |
This pull request has been removed from the queue for the following reason: The pull request can't be updated You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. If you want to requeue this pull request, you need to post a comment with the text: |
@mergify update |
❌ Mergify doesn't have permission to updateFor security reasons, Mergify can't update this pull request. Try updating locally. |
@mergify update |
☑️ Nothing to do
|
Pull request has been modified.
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
#26509
Reason for this change
AWS Step Functions has the functionality to call APIs in different regions according to the AWS blog: "You can extend this architecture to run workflows across multiple Regions or accounts." However, CDK syntax doesn't support it. This change will help expand the functionality of CDK to be able to call APIs where the API endpoint is not in the same region as the stack it's contained in (such as calling an API in a different AWS account).
Description of changes
This PR implements the solution suggested by pahud, which is to add an optional region parameter to the API endpoint getter (and to props to provide it).
Adding region to IRestApi was another option, but this would not be backwards-compatible (how would existing IRestApis determine the region?).
Ideally, I believe some
Region
enum would be superior to typestring
for region, but I looked around and couldn't find any other examples in the codebase and besides it might introduce coupling/dependency that isn't necessary. Instead, an invalid region such as "us-north-42" is likely to simply throw an exception for invalid API endpoint, which should expose the problem to the dev.This change supports an extra use-case of calling API endpoints in regions other than the region of the stack in which the API construct is defined. This uses AWS features of Step Functions invoking API Gateway endpoints in different regions.
Describe any new or updated permissions being added
None
Description of how you validated changes
Added a unit test with a hardcoded
us-west-2
in the style of other surrounding unit tests.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license