Skip to content

Commit

Permalink
add validation for StartingPosition when Stream is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
brettstack committed Jun 1, 2018
1 parent a26e50c commit e6d4910
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions samtranslator/model/eventsources/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def to_cloudformation(self, **kwargs):
if not self.Stream and not self.Queue:
raise InvalidEventException(
self.relative_id, "No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided.")

if self.Stream and not self.StartingPosition:
raise InvalidEventException(
self.relative_id, "StartingPosition is required for Kinesis and DynamoDB.")

lambda_eventsourcemapping.FunctionName = function_name_or_arn
lambda_eventsourcemapping.EventSourceArn = self.Stream or self.Queue
Expand Down
13 changes: 13 additions & 0 deletions tests/translator/input/error_missing_startingposition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Resources:
KinesisFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: s3://sam-demo-bucket/streams.zip
Handler: stream.kinesis_handler
Runtime: python2.7
Events:
MyKinesisStream:
Type: Kinesis
Properties:
Stream: arn:aws:kinesis:us-west-2:012345678901:stream/my-stream
BatchSize: 100
6 changes: 6 additions & 0 deletions tests/translator/output/error_missing_startingposition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"errors": [{
"errorMessage": "Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis and DynamoDB."
}],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis and DynamoDB."
}
1 change: 1 addition & 0 deletions tests/translator/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def test_transform_success(self, testcase, partition_with_region):
'error_function_with_invalid_deployment_preference_hook_property',
'error_invalid_logical_id',
'error_missing_queue',
'error_missing_startingposition',
'error_missing_stream',
'error_multiple_resource_errors',
'error_s3_not_in_template',
Expand Down

0 comments on commit e6d4910

Please sign in to comment.