From 2d11e8feb4bee67f2586d0c3169cd782980fae0f Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Tue, 8 Oct 2019 14:11:21 +0100 Subject: [PATCH] Code improvements --- moto/awslambda/models.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/moto/awslambda/models.py b/moto/awslambda/models.py index 2630abe1b..7d015a096 100644 --- a/moto/awslambda/models.py +++ b/moto/awslambda/models.py @@ -694,18 +694,15 @@ class LambdaBackend(BaseBackend): queue.lambda_event_source_mappings[esm.function_arn] = esm return esm - try: - stream = json.loads(dynamodbstreams_backends[self.region_name].describe_stream(spec['EventSourceArn'])) - spec.update({'FunctionArn': func.function_arn}) - esm = EventSourceMapping(spec) - self._event_source_mappings[esm.uuid] = esm - table_name = stream['StreamDescription']['TableName'] - table = dynamodb_backends2[self.region_name].get_table(table_name) - table.lambda_event_source_mappings[esm.function_arn] = esm - - return esm - except Exception: - pass # No DynamoDB stream exists + for stream in json.loads(dynamodbstreams_backends[self.region_name].list_streams())['Streams']: + if stream['StreamArn'] == spec['EventSourceArn']: + spec.update({'FunctionArn': func.function_arn}) + esm = EventSourceMapping(spec) + self._event_source_mappings[esm.uuid] = esm + table_name = stream['TableName'] + table = dynamodb_backends2[self.region_name].get_table(table_name) + table.lambda_event_source_mappings[esm.function_arn] = esm + return esm raise RESTError('ResourceNotFoundException', 'Invalid EventSourceArn') def publish_function(self, function_name): @@ -832,7 +829,7 @@ class LambdaBackend(BaseBackend): 'eventName': 'INSERT', 'eventVersion': item.to_json()['eventVersion'], 'eventSource': item.to_json()['eventSource'], - 'awsRegion': 'us-east-1', + 'awsRegion': self.region_name, 'dynamodb': item.to_json()['dynamodb'], 'eventSourceARN': source} for item in items]} func = self._lambdas.get_arn(function_arn)