aws-samples / serverless-test-samples Goto Github PK
View Code? Open in Web Editor NEWThis repository is designed to provide guidance for implementing comprehensive test suites for serverless applications.
License: MIT No Attribution
This repository is designed to provide guidance for implementing comprehensive test suites for serverless applications.
License: MIT No Attribution
The wording of the integration test instructions for the typescript-test-intro
sample should be clarified to show where to get the right value from, and how to set it when running the example tests. Ideally just include the right value in the stack outputs.
Examples:
https://img.shields.io/badge/Python-3.9-green
https://img.shields.io/badge/AWS-DynamoDB-blueviolet
https://img.shields.io/badge/Test-Unit-blue
https://img.shields.io/badge/Test-Integration-yellow (edited)
To be revised:
https://github.com/aws-samples/serverless-test-samples/blob/main/python-test-samples/apigw-lambda-layer/README.md
https://github.com/aws-samples/serverless-test-samples/blob/main/python-test-samples/apigw-lambda/README.md
https://github.com/aws-samples/serverless-test-samples/blob/main/python-test-samples/README.md
I think we will need to provide some examples of how developers can incorporate the async event listener pattern for async testing with their existing application.
Does EventBridge emit an event with a listener Lambda configured as target?
Does a Dynamo Stream get enabled and the listener Lambda is configured to read from the stream?
Feedback that there is too much log output in the unit tests for typescript-test-intro
, leading to confusion about if the test runs are successful or not.
Evaluate the output to determine if its working as expected. Consider suppressing logs during unit test runs (maybe with a logging lib like the Lambda PowerTools logger).
Invoking the Lambda function directly without specifying a event.json payload results in an error.
This is the case for both the SAM Lambda emulator as well as when invoking the Lambda directly in the cloud.
The following two commands referenced in the readme result in an error:
# run a unit test in a separate terminal
apigw-lambda-list-s3-buckets$ aws lambda invoke --function-name "ListBucketsFunction" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt
Also, the above is not really a unit test. It is more manual test.
Perhaps, only showing how to invoke the Lambda locally using 'sam local invoke is sufficient.
# invoke a Lambda function in the cloud using the AWS CLI
aws lambda invoke --function-name <function-name> outfile.txt
Error message in CloudWatch logs is:
[main] ERROR com.example.App - Http Method null is not supported
I believe the intent of these examples is to show how to invoke a Lambda directly both locally running in an emulator and in the cloud. Perhaps, include an additional scenario that is more appropriate/easier to test by invoking lambda directly that results in successful executions. Executions that result in errors give the impression that the user did something wrong. Also, these appear to be more manual tests which is also important from a developer experience perspective.
Update for:
Test AWS Lambda function handlers locally using mocks
Test AWS Lambda layers locally using mocks
The configured MemorySize of 3072 in the sam template.yaml
results in a a failed deployment in my aws account.
I changed it to 512 and it deployed and ran successfully.
Note: when you change the MemorySize to 512, you will need to run the sam build
command again before redeploying.
Here is the error I encountered:
nitiating deployment
=====================
Uploading to apigw-lambda-ddb/4ff0774d2555fab0b33b0d9e2e4d2915.template 1438 / 1438 (100.00%)
Waiting for changeset to be created..
CloudFormation stack changeset
---------------------------------------------------------------------------------------------------------
Operation LogicalResourceId ResourceType Replacement
---------------------------------------------------------------------------------------------------------
+ Add ticketAPIGatewayDeployme AWS::ApiGateway::Deploym N/A
nt7bc0b85f3d ent
+ Add ticketAPIGatewaydevStage AWS::ApiGateway::Stage N/A
+ Add ticketAPIGateway AWS::ApiGateway::RestApi N/A
+ Add ticketDDBTable AWS::DynamoDB::Table N/A
+ Add ticketLambdaPublisherApi AWS::Lambda::Permission N/A
EventsPermissiondev
+ Add ticketLambdaPublisherRol AWS::IAM::Role N/A
e
+ Add ticketLambdaPublisher AWS::Lambda::Function N/A
---------------------------------------------------------------------------------------------------------
Changeset created successfully. arn:aws:cloudformation:us-east-1:698566732460:changeSet/samcli-deploy1674055285/01730972-ec8e-43ec-86e5-19091d9dcc32
2023-01-18 10:21:37 - Waiting for stack create/update to complete
CloudFormation events from stack operations (refresh every 0.5 seconds)
---------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
---------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS AWS::DynamoDB::Table ticketDDBTable -
CREATE_IN_PROGRESS AWS::DynamoDB::Table ticketDDBTable Resource creation
Initiated
CREATE_COMPLETE AWS::DynamoDB::Table ticketDDBTable -
CREATE_IN_PROGRESS AWS::IAM::Role ticketLambdaPublisherRol -
e
CREATE_IN_PROGRESS AWS::IAM::Role ticketLambdaPublisherRol Resource creation
e Initiated
CREATE_COMPLETE AWS::IAM::Role ticketLambdaPublisherRol -
e
CREATE_IN_PROGRESS AWS::Lambda::Function ticketLambdaPublisher -
CREATE_IN_PROGRESS AWS::Lambda::Function ticketLambdaPublisher Resource creation
Initiated
CREATE_FAILED AWS::Lambda::Function ticketLambdaPublisher Resource handler
returned message:
"'MemorySize' value
failed to satisfy
constraint: Member must
have value less than or
equal to 3008 (Service:
Lambda, Status Code:
400, Request ID: c9ca047
c-f3f2-4404-82e6-1f59b66
60c8d)" (RequestToken: 0
82ec628-a402-90ed-6a5c-1
8f7eb139594,
HandlerErrorCode:
InvalidRequest)
ROLLBACK_IN_PROGRESS AWS::CloudFormation::Sta apigw-lambda-ddb The following
ck resource(s) failed to
create:
[ticketLambdaPublisher].
Rollback requested by
user.
DELETE_IN_PROGRESS AWS::Lambda::Function ticketLambdaPublisher -
DELETE_COMPLETE AWS::Lambda::Function ticketLambdaPublisher -
DELETE_IN_PROGRESS AWS::IAM::Role ticketLambdaPublisherRol -
e
DELETE_COMPLETE AWS::IAM::Role ticketLambdaPublisherRol -
e
DELETE_IN_PROGRESS AWS::DynamoDB::Table ticketDDBTable -
DELETE_COMPLETE AWS::DynamoDB::Table ticketDDBTable -
ROLLBACK_COMPLETE AWS::CloudFormation::Sta apigw-lambda-ddb -
ck
---------------------------------------------------------------------------------------------------------
Error: Failed to create/update the stack: apigw-lambda-ddb, Waiter StackCreateComplete failed: Waiter encountered a terminal failure state: For expression "Stacks[].StackStatus" we matched expected path: "ROLLBACK_COMPLETE" at least once
The configured MemorySize of 3072 in the sam template.yaml results in a a failed deployment in my aws account.
I changed it to 512 and it deployed and ran successfully.
Note: when you change the MemorySize to 512, you will need to run the sam build command again before redeploying.
Here is the error I encountered:
Initiating deployment
=====================
Uploading to apigw-lambda-ddb/4ff0774d2555fab0b33b0d9e2e4d2915.template 1438 / 1438 (100.00%)
Waiting for changeset to be created..
CloudFormation stack changeset
---------------------------------------------------------------------------------------------------------
Operation LogicalResourceId ResourceType Replacement
---------------------------------------------------------------------------------------------------------
+ Add ticketAPIGatewayDeployme AWS::ApiGateway::Deploym N/A
nt7bc0b85f3d ent
+ Add ticketAPIGatewaydevStage AWS::ApiGateway::Stage N/A
+ Add ticketAPIGateway AWS::ApiGateway::RestApi N/A
+ Add ticketDDBTable AWS::DynamoDB::Table N/A
+ Add ticketLambdaPublisherApi AWS::Lambda::Permission N/A
EventsPermissiondev
+ Add ticketLambdaPublisherRol AWS::IAM::Role N/A
e
+ Add ticketLambdaPublisher AWS::Lambda::Function N/A
---------------------------------------------------------------------------------------------------------
Changeset created successfully. arn:aws:cloudformation:us-east-1:698566732460:changeSet/samcli-deploy1674055285/01730972-ec8e-43ec-86e5-19091d9dcc32
2023-01-18 10:21:37 - Waiting for stack create/update to complete
CloudFormation events from stack operations (refresh every 0.5 seconds)
---------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
---------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS AWS::DynamoDB::Table ticketDDBTable -
CREATE_IN_PROGRESS AWS::DynamoDB::Table ticketDDBTable Resource creation
Initiated
CREATE_COMPLETE AWS::DynamoDB::Table ticketDDBTable -
CREATE_IN_PROGRESS AWS::IAM::Role ticketLambdaPublisherRol -
e
CREATE_IN_PROGRESS AWS::IAM::Role ticketLambdaPublisherRol Resource creation
e Initiated
CREATE_COMPLETE AWS::IAM::Role ticketLambdaPublisherRol -
e
CREATE_IN_PROGRESS AWS::Lambda::Function ticketLambdaPublisher -
CREATE_IN_PROGRESS AWS::Lambda::Function ticketLambdaPublisher Resource creation
Initiated
CREATE_FAILED AWS::Lambda::Function ticketLambdaPublisher Resource handler
returned message:
"'MemorySize' value
failed to satisfy
constraint: Member must
have value less than or
equal to 3008 (Service:
Lambda, Status Code:
400, Request ID: c9ca047
c-f3f2-4404-82e6-1f59b66
60c8d)" (RequestToken: 0
82ec628-a402-90ed-6a5c-1
8f7eb139594,
HandlerErrorCode:
InvalidRequest)
ROLLBACK_IN_PROGRESS AWS::CloudFormation::Sta apigw-lambda-ddb The following
ck resource(s) failed to
create:
[ticketLambdaPublisher].
Rollback requested by
user.
DELETE_IN_PROGRESS AWS::Lambda::Function ticketLambdaPublisher -
DELETE_COMPLETE AWS::Lambda::Function ticketLambdaPublisher -
DELETE_IN_PROGRESS AWS::IAM::Role ticketLambdaPublisherRol -
e
DELETE_COMPLETE AWS::IAM::Role ticketLambdaPublisherRol -
e
DELETE_IN_PROGRESS AWS::DynamoDB::Table ticketDDBTable -
DELETE_COMPLETE AWS::DynamoDB::Table ticketDDBTable -
ROLLBACK_COMPLETE AWS::CloudFormation::Sta apigw-lambda-ddb -
ck
---------------------------------------------------------------------------------------------------------
Error: Failed to create/update the stack: apigw-lambda-ddb, Waiter StackCreateComplete failed: Waiter encountered a terminal failure state: For expression "Stacks[].StackStatus" we matched expected path: "ROLLBACK_COMPLETE" at least once
Standardize Python samples on pip install (with optional Makefile)
Update the subsequent test cases too.
Invoking the Lambda function directly without specifying a event.json payload results in an error.
This is the case for both the SAM Lambda emulator as well as when invoking the Lambda directly in the cloud.
The following two commands referenced in the readme result in an error:
# run a unit test in a separate terminal
apigw-lambda-list-s3-buckets$ aws lambda invoke --function-name "ListBucketsFunction" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt
Also, the above is not really a unit test. It is more manual test.
Perhaps, only showing how to invoke the Lambda locally using 'sam local invoke is sufficient.
# invoke a Lambda function in the cloud using the AWS CLI
aws lambda invoke --function-name <function-name> outfile.txt
Error message in CloudWatch logs is:
[main] ERROR com.example.App - Http Method null is not supported
I believe the intent of these examples is to show how to invoke a Lambda directly both locally running in an emulator and in the cloud. Perhaps, include an additional scenario that is more appropriate/easier to test by invoking lambda directly that results in successful executions. Executions that result in errors give the impression that the user did something wrong. Also, these appear to be more manual tests which is also important from a developer experience perspective.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.