-
Notifications
You must be signed in to change notification settings - Fork 4k
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(aws-stepfunctions-tasks): allow region override in call-rest-api task #33252
base: main
Are you sure you want to change the base?
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.
The pull request linter fails with the following errors:
❌ The title scope of the pull request should omit 'aws-' from the name of modified packages. Use 'stepfunctions-tasks' instead of 'aws-stepfunctions-tasks'.
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.
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.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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