Python Test Samples Starter ProjectTesting in the Cloud2 min

Run integration tests against cloud resources

Integration tests run against deployed cloud resources. Since local unit tests cannot adequately test IAM permissions, our integration tests confirm that permissions are properly configured. Run integration tests against your deployed cloud resources with the following command:

# Set the environment variable AWS_SAM_STACK_NAME to the name of the stack you specified during deploy
 AWS_SAM_STACK_NAME=<stack-name> python3 -m pytest -s tests/integration -v

Invoke a Lambda function in the cloud

The AWS CLI enables you to invoke a Lambda function in the cloud.

# invoke a Lambda function in the cloud using the AWS CLI.  Substitute the function name as created in your stack.
 aws lambda invoke --function-name apigw-lambda-PythonTestDemo-6Ecinx8IauZv outfile.txt

Use SAM Accerate to speed up feedback cycles

AWS SAM Accelerate is a set of features that reduces deployment latency and enable developers to test their code quickly against production AWS services in the cloud. To learn more watch the video or read the blog post.

# synchronize local code with the cloud
 sam sync --watch --stack-name apigw-lambda

Now find the Lambda handler function in the src\app.py file. Make a change to the print statement on line 26 and notice what happens in your sync window.


Created by:

Dan Fox
Dan FoxDan Fox is a Principal Specialist Solutions Architect at AWS. Dan works with customers to help them leverage serverless services to build scalable, fault-tolerant, high-performing, cost-effective applications.
Rohan Mehta
Rohan MehtaAssociate Cloud Application Architect at AWS.