diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/http/integ.invoke.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/http/integ.invoke.ts index 6fdd0cc46498f..ae34a41b7fc28 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/http/integ.invoke.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/http/integ.invoke.ts @@ -65,7 +65,7 @@ const connection = new events.Connection(stack, 'Connection', { const httpInvokeTask = new tasks.HttpInvoke(stack, 'Invoke HTTP Endpoint', { apiRoot: api.urlForPath('/'), - apiEndpoint: sfn.TaskInput.fromText('/test'), + apiEndpoint: sfn.TaskInput.fromJsonPathAt('/test'), connection, method: sfn.TaskInput.fromText('GET'), }); diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md b/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md index 9f0a9dc800a48..6e0d09543b740 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md @@ -1375,7 +1375,7 @@ const connection = new events.Connection(this, 'Connection', { new tasks.HttpInvoke(this, 'Invoke HTTP API', { apiRoot: 'https://api.example.com', - apiEndpoint: sfn.TaskInput.fromText('path/to/resource'), + apiEndpoint: sfn.TaskInput.fromText(sfn.JsonPath.format('resource/{}/details', sfn.JsonPath.stringAt('$.resourceId'))), body: sfn.TaskInput.fromObject({ foo: 'bar' }), connection, headers: sfn.TaskInput.fromObject({ 'Content-Type': 'application/json' }), diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/http/invoke.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/http/invoke.ts index 04a29b774b12b..f6b2cfee5ad5b 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/http/invoke.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/http/invoke.ts @@ -166,7 +166,7 @@ export class HttpInvoke extends sfn.TaskStateBase { private buildTaskParameters() { const parameters: TaskParameters = { - ApiEndpoint: `${this.props.apiRoot}/${this.props.apiEndpoint.value}`, + ApiEndpoint: sfn.JsonPath.format('{}/{}', this.props.apiRoot, this.props.apiEndpoint.value), Authentication: { ConnectionArn: this.props.connection.connectionArn, }, diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/http/invoke.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/http/invoke.test.ts index e4ee324015363..0dd57ab5ca4b6 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/http/invoke.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/http/invoke.test.ts @@ -30,7 +30,10 @@ describe('AWS::StepFunctions::Tasks::HttpInvoke', () => { beforeEach(() => { stack = new cdk.Stack(); connection = new events.Connection(stack, 'Connection', { - authorization: events.Authorization.basic('username', cdk.SecretValue.unsafePlainText('password')), + authorization: events.Authorization.basic( + 'username', + cdk.SecretValue.unsafePlainText('password'), + ), connectionName: 'testConnection', }); }); @@ -44,11 +47,12 @@ describe('AWS::StepFunctions::Tasks::HttpInvoke', () => { }); expectTaskWithParameters(task, { - ApiEndpoint: 'https://api.example.com/path/to/resource', - Authentication: { + 'ApiEndpoint.$': + "States.Format('{}/{}', 'https://api.example.com', 'path/to/resource')", + 'Authentication': { ConnectionArn: stack.resolve(connection.connectionArn), }, - Method: 'POST', + 'Method': 'POST', }); }); @@ -68,22 +72,22 @@ describe('AWS::StepFunctions::Tasks::HttpInvoke', () => { }); expectTaskWithParameters(task, { - ApiEndpoint: 'https://api.example.com/path/to/resource', - Authentication: { + 'ApiEndpoint.$': "States.Format('{}/{}', 'https://api.example.com', 'path/to/resource')", + 'Authentication': { ConnectionArn: stack.resolve(connection.connectionArn), }, - Method: 'POST', - Headers: { + 'Method': 'POST', + 'Headers': { 'custom-header': 'custom-value', 'Content-Type': 'application/x-www-form-urlencoded', }, - Transform: { + 'Transform': { RequestBodyEncoding: 'URL_ENCODED', RequestEncodingOptions: { ArrayFormat: lib.URLEncodingFormat.BRACKETS, }, }, - QueryParameters: { + 'QueryParameters': { foo: 'bar', }, }); @@ -99,15 +103,15 @@ describe('AWS::StepFunctions::Tasks::HttpInvoke', () => { }); expectTaskWithParameters(task, { - ApiEndpoint: 'https://api.example.com/path/to/resource', - Authentication: { + 'ApiEndpoint.$': "States.Format('{}/{}', 'https://api.example.com', 'path/to/resource')", + 'Authentication': { ConnectionArn: stack.resolve(connection.connectionArn), }, - Method: 'POST', - Headers: { + 'Method': 'POST', + 'Headers': { 'Content-Type': 'application/x-www-form-urlencoded', }, - Transform: { + 'Transform': { RequestBodyEncoding: 'URL_ENCODED', }, }); @@ -123,11 +127,30 @@ describe('AWS::StepFunctions::Tasks::HttpInvoke', () => { }); expectTaskWithParameters(task, { - ApiEndpoint: 'https://api.example.com/path/to/resource', - Authentication: { + 'ApiEndpoint.$': "States.Format('{}/{}', 'https://api.example.com', 'path/to/resource')", + 'Authentication': { ConnectionArn: stack.resolve(connection.connectionArn), }, - Method: 'POST', + 'Method': 'POST', + }); + }); + + test('invoke with formatted apiEndpoint', () => { + const task = new lib.HttpInvoke(stack, 'Task', { + apiRoot: 'https://api.example.com', + apiEndpoint: sfn.TaskInput.fromText( + sfn.JsonPath.format('resource/{}/details', sfn.JsonPath.stringAt('$.resourceId')), + ), + connection, + method: sfn.TaskInput.fromText('POST'), + }); + expectTaskWithParameters(task, { + 'ApiEndpoint.$': + "States.Format('{}/{}', 'https://api.example.com', States.Format('resource/{}/details', $.resourceId))", + 'Authentication': { + ConnectionArn: stack.resolve(connection.connectionArn), + }, + 'Method': 'POST', }); }); });