Skip to content

Repository files navigation

Event Mocks

A small library that includes details mocks of AWS Lambda event sources. Useful for use when unit testing your Lambda functions. Supported Event Sources are:

  • API Gateway
  • SNS
  • SQS
  • DynamoDB
  • S3
  • Scheduled
  • Websocket
  • Alexa Skill
  • Alexa Smart Home
  • CloudWatch
  • CloudWatch Log
  • Cognito Pool
  • IoT

The library simply uses default event source mock templates and merge it with any overwrite you provide. Check out the JSON template files to learn more about the data structure of each event source.

Usage

SNS

importcreateEventfrom"@serverless/event-mocks"constmocked=createEvent("aws:sns",{Records: [{Sns: {Message: "trigger-email"}}]});

API Gateway

importcreateEventfrom"@serverless/event-mocks"constevent=createEvent("aws:apiGateway",{body: {first_name: "Sam",last_name: "Smith"}});

S3

importcreateEventfrom"@serverless/event-mocks"constevent=createEvent("aws:s3",{Records: [{eventName: "ObjectCreated:Put",s3: {bucket: {name: "my-bucket-name"},object: {key: "object-key"}}}]});

Scheduled

importcreateEventfrom"@serverless/event-mocks"constevent=createEvent("aws:scheduled",{region: "us-west-2"});

Kinesis

importcreateEventfrom"@serverless/event-mocks"constevent=createEvent("aws:kinesis",{data: newBuffer("this is test data").toString("base64")});

Dynamo

importcreateEventfrom"@serverless/event-mocks"constevent=createEvent("aws:dynamo",{Records: [{eventID: "1",eventVersion: "1.0",dynamodb: {Keys: {Id: {N: "101"}},NewImage: {Message: {S: "New item!"},Id: {N: "101"}},StreamViewType: "NEW_AND_OLD_IMAGES",SequenceNumber: "111",SizeBytes: 26},awsRegion: "us-west-2",eventName: "INSERT",eventSourceARN: "arn:aws:dynamodb:us-east-1:123456789012:table/images",eventSource: "aws:dynamodb"}]});

Websocket event

constevent=createEvent("aws:websocket",{body: {first_name: "Sam",last_name: "Smith",},requestContext: {connectedAt: 123,connectionId: "abc123",},});

CloudWatch event

constevent=createEvent("aws:cloudWatch",{"detail-type": "Something has been deleted.","region": "us-east-1"});

CloudWatchLog event

constevent=createEvent("aws:cloudWatchLog",{awslogs: {data: "Some gzipped, then base64 encoded data",}});

Alexa Skill event

constevent=createEvent("aws:alexaSkill",{request: {type: "CanFulfillIntentRequest",},context: {System: {device: {deviceId: "myDevice",},},},}

Alexa SmartHome event

constevent=createEvent("aws:alexaSmartHome",{payload: {switchControlAction: "TURN_OFF",},}

IoT event

constevent=createEvent("aws:iot",{this: {can: {be: "anything I want",},}

Cognito Pool Event

constevent=createEvent("aws:cognitoUserPool",{userName: "Aaron Stuyvenberg",}

About

No description, website, or topics provided.

Resources

Stars

74 stars

Watchers

18 watching

Forks

Releases

Packages

Used by

Contributors

Languages