


#Python lambda manual
AWS Lambda manual testingįor manual testing of your AWS Lambda function, you should have: Let’s start with the manual testing, first. Unit test AWS Lambda automatically before the deployment.So, how can we ensure that the code above is working? The code itself is self-explanatory, so we’ll not spend time describing it and move straight to the testing. S3_bucket = recordĭata = get_data_from_file(s3_bucket, s3_file) Result = DYNAMODB_TABLE.put_item(Item=data) ('%s/%s file content: %s', bucket, key, data) Response = S3_CLIENT.get_object(Bucket=bucket, Key=key) Simple Lambda function that reads file from S3 bucket and savesĪWS_REGION = os.environ.get('AWS_REGION', 'us-east-1')ĭB_TABLE_NAME = os.environ.get('DB_TABLE_NAME', 'amaksimov-test')ĭYNAMODB_CLIENT = boto3.resource('dynamodb', region_name=AWS_REGION)ĭYNAMODB_TABLE = DYNAMODB_CLIENT.Table(DB_TABLE_NAME)įunction reads json file uploaded to S3 bucket Here’s the Lambda function code that we’re going to test: ''' Upload event – we need to ensure that our Lambda function can process standard events from the S3 bucket.Save the file to DynamoDB – we need to ensure that our Lambda function code can save the file to DynamoDB of the specified structure.File download – we need to make sure that our Lambda function can download, read and parse the file.File upload to S3 – we need to make sure that during the test cycle, we’ll be dealing with the same file and the same content.So, here are several places which need to be tested: Related articles AWS Lambda function exampleįor example, let’s test a Lambda function that reads the file uploaded to the S3 bucket and saves its content to DynamoDB.Unit-testing AWS Lambda DynamoDB operations.Unit-testing AWS Lambda S3 file upload events.

