Skip to content

Commit

Permalink
remove payloadResponseOnly and switch by integrationPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
tmokmss committed Feb 6, 2025
1 parent 604bb29 commit 31c4e3c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class TestStack extends cdk.Stack {
region: targetRegion,
resultPath: sfn.JsonPath.DISCARD,
integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
payloadResponseOnly: false,
});

this.stateMachine = new sfn.StateMachine(this, 'StateMachine', {
Expand Down
2 changes: 2 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ const getObject = new tasks.CallAwsServiceCrossRegion(this, 'GetObject', {

Other properties such as `additionalIamStatements` can be used in the same way as the `CallAwsService` task.

Note that when you use `integrationPattern.WAIT_FOR_TASK_TOKEN`, the output path changes under `Payload` property.

## Athena

Step Functions supports [Athena](https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html) through the service integration pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ interface CallAwsServiceCrossRegionOptions {
*/
readonly endpoint?: string;

/**
* Invoke the Lambda in a way that only returns the payload response without additional metadata.
*
* The `payloadResponseOnly` property cannot be true if `integrationPattern` is specified.
* If true, it always uses the REQUEST_RESPONSE behavior.
*
* @default true
*/
readonly payloadResponseOnly?: boolean;

/**
* Whether to retry on the backend Lambda service exceptions.
*
Expand Down Expand Up @@ -145,19 +135,15 @@ export class CallAwsServiceCrossRegion extends sfn.TaskStateBase {
protected readonly taskPolicies?: iam.PolicyStatement[];
protected readonly lambdaFunction: IFunction;

private readonly payloadResponseOnly: boolean;
private readonly integrationPattern: sfn.IntegrationPattern | undefined;

constructor(scope: Construct, id: string, private readonly props: CallAwsServiceCrossRegionProps) {
super(scope, id, props);

this.payloadResponseOnly = props.payloadResponseOnly ?? true;
this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE;

if (props.integrationPattern === sfn.IntegrationPattern.RUN_JOB) {
throw new Error('The RUN_JOB integration pattern is not supported for CallAwsService');
}

if (this.payloadResponseOnly && props.integrationPattern === sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN) {
throw new Error("The 'payloadResponseOnly' property cannot be true if integrationPattern is set to WAIT_FOR_TASK_TOKEN");
throw new Error('The RUN_JOB integration pattern is not supported for CallAwsServiceCrossRegion');
}

if (!Token.isUnresolved(props.action) && !props.action.startsWith(props.action[0]?.toLowerCase())) {
Expand Down Expand Up @@ -216,7 +202,7 @@ export class CallAwsServiceCrossRegion extends sfn.TaskStateBase {
*/
protected _renderTask(topLevelQueryLanguage?: sfn.QueryLanguage): any {
const queryLanguage = sfn._getActualQueryLanguage(topLevelQueryLanguage, this.props.queryLanguage);
if (this.payloadResponseOnly) {
if (this.integrationPattern === sfn.IntegrationPattern.REQUEST_RESPONSE) {
return {
Resource: this.lambdaFunction.functionArn,
...this._renderParametersOrArguments({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,23 +328,6 @@ test('can pass additional IAM statements', () => {
});
});

test('throws if integrationPattern is WAIT_FOR_TASK_TOKEN but payloadResponseOnly=true', () => {
expect(
() =>
new tasks.CallAwsServiceCrossRegion(stack, 'GetObject', {
service: 's3',
action: 'GetObject',
parameters: {
Bucket: 'my-bucket',
Key: sfn.JsonPath.stringAt('$.key'),
},
region: 'us-east-1',
iamResources: ['*'],
integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
}),
).toThrow(/The 'payloadResponseOnly' property cannot be true/);
});

test('integrationPattern is WAIT_FOR_TASK_TOKEN', () => {
// WHEN
const task = new tasks.CallAwsServiceCrossRegion(stack, 'StartExecution', {
Expand All @@ -360,7 +343,6 @@ test('integrationPattern is WAIT_FOR_TASK_TOKEN', () => {
}),
},
iamResources: ['*'],
payloadResponseOnly: false,
});
new sfn.StateMachine(stack, 'StateMachine', {
definitionBody: sfn.DefinitionBody.fromChainable(task),
Expand Down

0 comments on commit 31c4e3c

Please sign in to comment.