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

fix(stepfunctions-tasks): allow passing apiEndpoint as intrinsic function #31643

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
});
Expand All @@ -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',
});
});

Expand All @@ -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',
},
});
Expand All @@ -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',
},
});
Expand All @@ -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',
});
});
});
Loading