-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(stepfunctions): fix passing of Token in RunLambdaTask (#2939)
Fixes #2937.
- Loading branch information
Showing
14 changed files
with
221 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/@aws-cdk/aws-stepfunctions-tasks/test/run-lambda-task.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import '@aws-cdk/assert/jest'; | ||
import lambda = require('@aws-cdk/aws-lambda'); | ||
import sfn = require('@aws-cdk/aws-stepfunctions'); | ||
import { Stack } from '@aws-cdk/cdk'; | ||
import tasks = require('../lib'); | ||
|
||
let stack: Stack; | ||
let fn: lambda.Function; | ||
beforeEach(() => { | ||
stack = new Stack(); | ||
fn = new lambda.Function(stack, 'Fn', { | ||
code: lambda.Code.inline('hello'), | ||
handler: 'index.hello', | ||
runtime: lambda.Runtime.Python27, | ||
}); | ||
}); | ||
|
||
test('Invoke lambda with default magic ARN', () => { | ||
const task = new sfn.Task(stack, 'Task', { | ||
task: new tasks.RunLambdaTask(fn, { | ||
payload: { | ||
foo: 'bar' | ||
}, | ||
invocationType: tasks.InvocationType.RequestResponse, | ||
clientContext: "eyJoZWxsbyI6IndvcmxkIn0=", | ||
qualifier: "1", | ||
}) | ||
}); | ||
new sfn.StateMachine(stack, 'SM', { | ||
definition: task | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::StepFunctions::StateMachine', { | ||
DefinitionString: { | ||
"Fn::Join": ["", [ | ||
"{\"StartAt\":\"Task\",\"States\":{\"Task\":{\"End\":true,\"Parameters\":{\"FunctionName\":\"", | ||
{ Ref: "Fn9270CBC0" }, | ||
"\",\"Payload\":{\"foo\":\"bar\"},\"InvocationType\":\"RequestResponse\",\"ClientContext\":\"eyJoZWxsbyI6IndvcmxkIn0=\"," | ||
+ "\"Qualifier\":\"1\"},\"Type\":\"Task\",\"Resource\":\"arn:aws:states:::lambda:invoke\"}}}" | ||
]] | ||
}, | ||
}); | ||
}); | ||
|
||
test('Lambda function can be used in a Task with Task Token', () => { | ||
const task = new sfn.Task(stack, 'Task', { | ||
task: new tasks.RunLambdaTask(fn, { | ||
waitForTaskToken: true, | ||
payload: { | ||
token: sfn.Context.taskToken | ||
} | ||
}) | ||
}); | ||
new sfn.StateMachine(stack, 'SM', { | ||
definition: task | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::StepFunctions::StateMachine', { | ||
DefinitionString: { | ||
"Fn::Join": ["", [ | ||
"{\"StartAt\":\"Task\",\"States\":{\"Task\":{\"End\":true,\"Parameters\":{\"FunctionName\":\"", | ||
{ Ref: "Fn9270CBC0" }, | ||
"\",\"Payload\":{\"token.$\":\"$$.Task.Token\"}},\"Type\":\"Task\",\"Resource\":\"arn:aws:states:::lambda:invoke.waitForTaskToken\"}}}" | ||
]] | ||
}, | ||
}); | ||
}); | ||
|
||
test('Task throws if waitForTaskToken is supplied but task token is not included in payLoad', () => { | ||
expect(() => { | ||
new sfn.Task(stack, 'Task', { | ||
task: new tasks.RunLambdaTask(fn, { | ||
waitForTaskToken: true | ||
}) | ||
}); | ||
}).toThrow(/Task Token is missing in payload/i); | ||
}); |
Oops, something went wrong.