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(aws-stepfunctions, aws-stepfunctions-tasks): missing suffix in fi… #2939

Merged
merged 5 commits into from
Jun 21, 2019
Merged
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
Prev Previous commit
feat(aws-stepfunctions-tasks) complete supporting parameters for lambda
* Add Qualifier in the list of supporting parameters for lambda
* Increase unit test coverage for all the services which support "waitForTaskToken"
  • Loading branch information
wqzoww committed Jun 21, 2019
commit 125a259f9a204d3d0ef00a18317382b681309726
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export interface RunLambdaTaskProps {
* @default - No context
*/
readonly clientContext?: string;

/**
* Version or alias of the function to be invoked
*
* @default - No qualifier
*/
readonly qualifier?: string;
}

/**
Expand Down Expand Up @@ -75,6 +82,7 @@ export class RunLambdaTask implements sfn.IStepFunctionsTask {
Payload: this.props.payload,
InvocationType: this.props.invocationType,
ClientContext: this.props.clientContext,
Qualifier: this.props.qualifier
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import sfn = require('@aws-cdk/aws-stepfunctions');
import cdk = require('@aws-cdk/cdk');
import tasks = require('../lib');

test('publish to SNS', () => {
test('Publish literal message to SNS topic', () => {
// GIVEN
const stack = new cdk.Stack();
const topic = new sns.Topic(stack, 'Topic');

// WHEN
const pub = new sfn.Task(stack, 'Publish', { task: new tasks.PublishToTopic(topic, {
message: sfn.TaskInput.fromText('Send this message')
message: sfn.TaskInput.fromText('Publish this message')
}) });

// THEN
Expand All @@ -20,43 +20,62 @@ test('publish to SNS', () => {
End: true,
Parameters: {
TopicArn: { Ref: 'TopicBFC7AF6E' },
Message: 'Send this message'
Message: 'Publish this message'
},
});
});

test('publish to topic with ARN from payload', () => {
test('Publish JSON to SNS topic with task token', () => {
// GIVEN
const stack = new cdk.Stack();
const topic = sns.Topic.fromTopicArn(stack, 'Topic', sfn.Data.stringAt('$.topicArn'));
const topic = new sns.Topic(stack, 'Topic');

// WHEN
const pub = new sfn.Task(stack, 'Publish', { task: new tasks.PublishToTopic(topic, {
message: sfn.TaskInput.fromText('Send this message')
waitForTaskToken: true,
message: sfn.TaskInput.fromObject({
Input: 'Publish this message',
Token: sfn.Context.taskToken
})
}) });

// THEN
expect(stack.resolve(pub.toStateJson())).toEqual({
Type: 'Task',
Resource: 'arn:aws:states:::sns:publish',
Resource: 'arn:aws:states:::sns:publish.waitForTaskToken',
End: true,
Parameters: {
'TopicArn.$': '$.topicArn',
'Message': 'Send this message'
TopicArn: { Ref: 'TopicBFC7AF6E' },
Message: {
'Input': 'Publish this message',
'Token.$': '$$.Task.Token'
}
},
});
});

test('publish JSON to SNS', () => {
test('Task throws if waitForTaskToken is supplied but task token is not included in message', () => {
expect(() => {
// GIVEN
const stack = new cdk.Stack();
const topic = new sns.Topic(stack, 'Topic');
// WHEN
new sfn.Task(stack, 'Publish', { task: new tasks.PublishToTopic(topic, {
waitForTaskToken: true,
message: sfn.TaskInput.fromText('Publish this message')
}) });
// THEN
}).toThrow(/Task Token is missing in message/i);
});

test('Publish to topic with ARN from payload', () => {
// GIVEN
const stack = new cdk.Stack();
const topic = new sns.Topic(stack, 'Topic');
const topic = sns.Topic.fromTopicArn(stack, 'Topic', sfn.Data.stringAt('$.topicArn'));

// WHEN
const pub = new sfn.Task(stack, 'Publish', { task: new tasks.PublishToTopic(topic, {
message: sfn.TaskInput.fromObject({
Input: 'Send this message'
})
message: sfn.TaskInput.fromText('Publish this message')
}) });

// THEN
Expand All @@ -65,10 +84,8 @@ test('publish JSON to SNS', () => {
Resource: 'arn:aws:states:::sns:publish',
End: true,
Parameters: {
TopicArn: { Ref: 'TopicBFC7AF6E' },
Message: {
Input: 'Send this message'
}
'TopicArn.$': '$.topicArn',
'Message': 'Publish this message'
},
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ test('Invoke lambda with default magic ARN', () => {
task: new tasks.RunLambdaTask(fn, {
payload: {
foo: 'bar'
}
},
invocationType: tasks.InvocationType.RequestResponse,
clientContext: "eyJoZWxsbyI6IndvcmxkIn0=",
qualifier: "1",
})
});
new sfn.StateMachine(stack, 'SM', {
Expand All @@ -32,7 +35,8 @@ test('Invoke lambda with default magic ARN', () => {
"Fn::Join": ["", [
"{\"StartAt\":\"Task\",\"States\":{\"Task\":{\"End\":true,\"Parameters\":{\"FunctionName\":\"",
{ Ref: "Fn9270CBC0" },
"\",\"Payload\":{\"foo\":\"bar\"}},\"Type\":\"Task\",\"Resource\":\"arn:aws:states:::lambda:invoke\"}}}"
"\",\"Payload\":{\"foo\":\"bar\"},\"InvocationType\":\"RequestResponse\",\"ClientContext\":\"eyJoZWxsbyI6IndvcmxkIn0=\","
+ "\"Qualifier\":\"1\"},\"Type\":\"Task\",\"Resource\":\"arn:aws:states:::lambda:invoke\"}}}"
]]
},
});
Expand Down Expand Up @@ -62,7 +66,7 @@ test('Lambda function can be used in a Task with Task Token', () => {
});
});

test('Task throws if waitForTaskToken is supplied but task token is not included', () => {
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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ beforeEach(() => {
queue = new sqs.Queue(stack, 'Queue');
});

test('publish to queue', () => {
test('Send message to queue', () => {
// WHEN
const pub = new sfn.Task(stack, 'Send', { task: new tasks.SendToQueue(queue, {
const task = new sfn.Task(stack, 'Send', { task: new tasks.SendToQueue(queue, {
messageBody: sfn.TaskInput.fromText('Send this message'),
messageDeduplicationId: sfn.Data.stringAt('$.deduping'),
}) });

// THEN
expect(stack.resolve(pub.toStateJson())).toEqual({
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: 'arn:aws:states:::sqs:sendMessage',
End: true,
Expand All @@ -32,16 +32,52 @@ test('publish to queue', () => {
});
});

test('message body can come from state', () => {
test('Send message to SQS queue with task token', () => {
// WHEN
const pub = new sfn.Task(stack, 'Send', {
const task = new sfn.Task(stack, 'Send', { task: new tasks.SendToQueue(queue, {
waitForTaskToken: true,
messageBody: sfn.TaskInput.fromObject({
Input: 'Send this message',
Token: sfn.Context.taskToken
})
}) });

// THEN
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: 'arn:aws:states:::sqs:sendMessage.waitForTaskToken',
End: true,
Parameters: {
QueueUrl: { Ref: 'Queue4A7E3555' },
MessageBody: {
'Input': 'Send this message',
'Token.$': '$$.Task.Token'
}
},
});
});

test('Task throws if waitForTaskToken is supplied but task token is not included in messageBody', () => {
expect(() => {
// WHEN
new sfn.Task(stack, 'Send', { task: new tasks.SendToQueue(queue, {
waitForTaskToken: true,
messageBody: sfn.TaskInput.fromText('Send this message')
}) });
// THEN
}).toThrow(/Task Token is missing in messageBody/i);
});

test('Message body can come from state', () => {
// WHEN
const task = new sfn.Task(stack, 'Send', {
task: new tasks.SendToQueue(queue, {
messageBody: sfn.TaskInput.fromDataAt('$.theMessage')
})
});

// THEN
expect(stack.resolve(pub.toStateJson())).toEqual({
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: 'arn:aws:states:::sqs:sendMessage',
End: true,
Expand All @@ -52,9 +88,9 @@ test('message body can come from state', () => {
});
});

test('message body can be an object', () => {
test('Message body can be an object', () => {
// WHEN
const pub = new sfn.Task(stack, 'Send', {
const task = new sfn.Task(stack, 'Send', {
task: new tasks.SendToQueue(queue, {
messageBody: sfn.TaskInput.fromObject({
literal: 'literal',
Expand All @@ -64,7 +100,7 @@ test('message body can be an object', () => {
});

// THEN
expect(stack.resolve(pub.toStateJson())).toEqual({
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: 'arn:aws:states:::sqs:sendMessage',
End: true,
Expand All @@ -78,9 +114,9 @@ test('message body can be an object', () => {
});
});

test('message body object can contain references', () => {
test('Message body object can contain references', () => {
// WHEN
const pub = new sfn.Task(stack, 'Send', {
const task = new sfn.Task(stack, 'Send', {
task: new tasks.SendToQueue(queue, {
messageBody: sfn.TaskInput.fromObject({
queueArn: queue.queueArn
Expand All @@ -89,7 +125,7 @@ test('message body object can contain references', () => {
});

// THEN
expect(stack.resolve(pub.toStateJson())).toEqual({
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: 'arn:aws:states:::sqs:sendMessage',
End: true,
Expand Down