Running and debugging your AWS Lambda code locally
Sometimes you want to simulate an API Gateway payload with a local Lambda against a real instance of remote DynamoDB hosted in AWS. This allows you to debug and build up unit tests with real data. In addition, we will see how these can later be used in the integration test.
Batch-loading data into DynamoDB
We will first discuss how to batch-load data into DynamoDB from a comma-separated values (CSV) file called sample_data/dynamodb-sample-data.txt
. Rather than insert an individual statement for each item, this is a much more efficient process, as the data file is decoupled from the Python code:
EventId,EventDay,EventCount 324,20171010,2 324,20171012,10 324,20171013,10 324,20171014,6 324,20171016,6 324,20171017,2 300,20171011,1 300,20171013,3 300,20171014,30
Add another method, called update_dynamo_event_counter()
, that updates DynamoDB records using the DynamoRepository
class.
Here are the contents of the serverless-microservice-data-api/aws_dynamo...