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

feat(stepfunctions-tasks): allow region override in call-rest-api task #33252

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export interface CallApiGatewayRestApiEndpointProps extends CallApiGatewayEndpoi
* Name of the stage where the API is deployed to in API Gateway
*/
readonly stageName: string;

/**
* 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* 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`.

*/
readonly region?: string;
}

/**
Expand Down Expand Up @@ -56,15 +63,15 @@ export class CallApiGatewayRestApiEndpoint extends CallApiGatewayEndpointBase {
constructor(scope: Construct, id: string, private readonly props: CallApiGatewayRestApiEndpointProps) {
super(scope, id, props);

this.apiEndpoint = this.getApiEndpoint();
this.apiEndpoint = this.getApiEndpoint(props.region);
this.arnForExecuteApi = props.api.arnForExecuteApi(props.method, props.apiPath, props.stageName);
this.stageName = props.stageName;

this.taskPolicies = this.createPolicyStatements();
}

private getApiEndpoint(): string {
private getApiEndpoint(region?: string): string {
const apiStack = cdk.Stack.of(this.props.api);
return `${this.props.api.restApiId}.execute-api.${apiStack.region}.${apiStack.urlSuffix}`;
return `${this.props.api.restApiId}.execute-api.${region ?? apiStack.region}.${apiStack.urlSuffix}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,59 @@ describe('CallApiGatewayRestApiEndpoint', () => {
});
});

test('provide region override', () => {
// GIVEN
const stack = new cdk.Stack();
const restApi = new apigateway.RestApi(stack, 'RestApi');
const region = 'us-west-2';

// WHEN
const task = new CallApiGatewayRestApiEndpoint(stack, 'Call', {
api: restApi,
method: HttpMethod.GET,
stageName: 'dev',
region: region,
});

// THEN
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
End: true,
Parameters: {
ApiEndpoint: {
'Fn::Join': [
'',
[
{
Ref: 'RestApi0C43BF4B',
},
`.execute-api.${region}.`,
{
Ref: 'AWS::URLSuffix',
},
],
],
},
AuthType: 'NO_AUTH',
Method: 'GET',
Stage: 'dev',
},
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':states:::apigateway:invoke',
],
],
},
});
});


test('wait for task token', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Loading