Giter Site home page Giter Site logo

aws-samples / serverless-test-samples Goto Github PK

View Code? Open in Web Editor NEW
276.0 16.0 77.0 46.64 MB

This repository is designed to provide guidance for implementing comprehensive test suites for serverless applications.

License: MIT No Attribution

Python 21.48% C# 37.28% PowerShell 0.06% Shell 0.11% JavaScript 2.72% TypeScript 12.66% Java 18.44% Makefile 0.76% Velocity Template Language 0.77% Groovy 0.46% HTML 4.43% CSS 0.69% Dockerfile 0.15%
dotnet java patterns python serverless testing typescript

serverless-test-samples's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

serverless-test-samples's Issues

Add Shields to Python documentation

Research best ways to emit events to async event listener Lambda function

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?

Java: apigw-lambda-list-s3-buckets example- invoking the lambda function directly results in 405 error

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:

  1. Invoke a Lambda locally
# 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.

  1. Invoke a Lambda in the cloud
# 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

Summary

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.

Java: Apigw-lambda-ddb example : configured MemorySize is too high and results in a failed deployment in my account

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

Java: Apigw-lambda-ddb example : configured MemorySize is too high and results in a failed deployment in my account

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

Java: apigw-lambda-list-s3-buckets example- invoking the lambda function directly results in 405 error

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:

  1. Invoke a Lambda locally
# 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.

  1. Invoke a Lambda in the cloud
# 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

Summary

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.