Skip to content

Commit

Permalink
Raise exception on invalid event source type and use full spec
Browse files Browse the repository at this point in the history
  • Loading branch information
rwestergren committed Aug 22, 2019
1 parent 819dcfe commit 1efd9ee
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions moto/awslambda/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ def __init__(self, spec):
self.event_source_arn = spec['EventSourceArn']
self.uuid = str(uuid.uuid4())
self.last_modified = time.mktime(datetime.datetime.utcnow().timetuple())
self.batch_size = '' # Default to blank

# BatchSize service default/max mapping
batch_size_map = {
Expand All @@ -453,6 +452,9 @@ def __init__(self, spec):
"BatchSize {} exceeds the max of {}".format(batch_size, batch_size_entry[1]))
else:
self.batch_size = batch_size
else:
raise ValueError("InvalidParameterValueException",
"Unsupported event source type")

# optional
self.starting_position = spec.get('StartingPosition', 'TRIM_HORIZON')
Expand Down Expand Up @@ -668,7 +670,7 @@ def create_event_source_mapping(self, spec):
raise RESTError('InvalidParameterValueException', 'Missing {}'.format(param))

# Validate function name
func = self._lambdas.get_function_by_name_or_arn(spec.get('FunctionName', ''))
func = self._lambdas.get_function_by_name_or_arn(spec.pop('FunctionName', ''))
if not func:
raise RESTError('ResourceNotFoundException', 'Invalid FunctionName')

Expand All @@ -682,11 +684,8 @@ def create_event_source_mapping(self, spec):
raise RESTError('InvalidParameterValueException',
'{} is FIFO'.format(queue.queue_arn))
else:
esm_spec = {
'EventSourceArn': spec['EventSourceArn'],
'FunctionArn': func.function_arn,
}
esm = EventSourceMapping(esm_spec)
spec.update({'FunctionArn': func.function_arn})
esm = EventSourceMapping(spec)
self._event_source_mappings[esm.uuid] = esm

# Set backend function on queue
Expand Down

0 comments on commit 1efd9ee

Please sign in to comment.