Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions samtranslator/model/eventsources/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from samtranslator.model.exceptions import InvalidEventException
from samtranslator.model.iam import IAMRolePolicies
from samtranslator.utils.types import Intrinsicable
from samtranslator.validator.value_validator import sam_expect


class PullEventSource(ResourceMacro):
Expand Down Expand Up @@ -155,9 +156,12 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def]

destination_config_policy = None
if self.DestinationConfig:
on_failure = self.DestinationConfig.get("OnFailure")
if on_failure is None:
raise InvalidEventException(self.logical_id, "'OnFailure' is a required field for 'DestinationConfig'")
on_failure: Dict[str, Any] = sam_expect(
self.DestinationConfig.get("OnFailure"),
self.logical_id,
"DestinationConfig.OnFailure",
is_sam_event=True,
).to_be_a_map()

# `Type` property is for sam to attach the right policies
destination_type = on_failure.get("Type")
Expand Down
10 changes: 5 additions & 5 deletions samtranslator/validator/value_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
else:
self.resource_logical_id = resource_id

def to_be_a(self, expected_type: ExpectedType, message: Optional[str] = "") -> Optional[T]:
def to_be_a(self, expected_type: ExpectedType, message: Optional[str] = "") -> T:
"""
Validate the type of the value and return the value if valid.

Expand Down Expand Up @@ -69,16 +69,16 @@ def to_not_be_none(self, message: Optional[str] = "") -> T:
#
# alias methods:
#
def to_be_a_map(self, message: Optional[str] = "") -> Optional[T]:
def to_be_a_map(self, message: Optional[str] = "") -> T:
return self.to_be_a(ExpectedType.MAP, message)

def to_be_a_list(self, message: Optional[str] = "") -> Optional[T]:
def to_be_a_list(self, message: Optional[str] = "") -> T:
return self.to_be_a(ExpectedType.LIST, message)

def to_be_a_string(self, message: Optional[str] = "") -> Optional[T]:
def to_be_a_string(self, message: Optional[str] = "") -> T:
return self.to_be_a(ExpectedType.STRING, message)

def to_be_an_integer(self, message: Optional[str] = "") -> Optional[T]:
def to_be_an_integer(self, message: Optional[str] = "") -> T:
return self.to_be_a(ExpectedType.INTEGER, message)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Parameters:
Description: parameter for batching window in seconds

Resources:
MyFunction:
MyFunctionWithMissingOnFailure:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Expand Down Expand Up @@ -36,6 +36,35 @@ Resources:
Type: SNS
Destination: !Ref MySnsTopic

MyFunctionWithInvalidOnFailureType:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
InlineCode: |
exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify(event),
headers: {}
}
}
Runtime: nodejs12.x
Policies:
- SQSSendMessagePolicy:
QueueName: !GetAtt MySqsQueue.QueueName
Events:
StreamEvent:
Type: Kinesis
Properties:
Stream: !GetAtt KinesisStream.Arn
MaximumBatchingWindowInSeconds: !Ref MyBatchingWindowParam
StartingPosition: LATEST
DestinationConfig:
InvalidConfig:
Type: SNS
Destination: !Ref MySnsTopic
OnFailure: this should be a dict

KinesisStream:
Type: AWS::Kinesis::Stream
Properties:
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyFunctionWithInvalidOnFailureType] is invalid. Event with id [MyFunctionWithInvalidOnFailureTypeStreamEvent] is invalid. Property 'DestinationConfig.OnFailure' should be a map. Resource with id [MyFunctionWithMissingOnFailure] is invalid. Event with id [MyFunctionWithMissingOnFailureStreamEvent] is invalid. Property 'DestinationConfig.OnFailure' should be a map."
}

This file was deleted.