forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aws-stepfunctions, aws-stepfunctions-tasks): missing suffix in fi…
…eld names of reference paths * add suffix ".$" for the fields whose values are reference paths, including json path and context object * fix unit tests and integration test for lambda task issue: aws#2937
- Loading branch information
Showing
6 changed files
with
104 additions
and
44 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
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
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' | ||
} | ||
}) | ||
}); | ||
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\"}},\"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', () => { | ||
expect(() => { | ||
new sfn.Task(stack, 'Task', { | ||
task: new tasks.RunLambdaTask(fn, { | ||
waitForTaskToken: true | ||
}) | ||
}); | ||
}).toThrow(/Task Token is missing in payload/i); | ||
}); |
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