Code Monkey home page Code Monkey logo

sqs_with_sls_example's Introduction

Example SQS using Serverless

Serverless implementation of SQS, with a DLQ and processing NodeJS Function

Deploy

npm i and all that.

Decide AWS account you are deploying and do the thing you do to access it. I suggest using aws-vault

  • set the service and QueueName (default set to exampleSQS)
  • npm run deploy
  • Get the URL: aws sqs get-queue-url --queue-name exampleSQSQueue --output text |head
  • Watch the logs: aws logs tail /aws/lambda/exampleSQS-dev-processMessage --follow
  • In a separate terminal, call the SQS url with a message: http -v https://sqs.eu-west-1.amazonaws.com/YOUR_AWS_ACCOUNT_ID/exampleQueue Action==SendMessage MessageBody=='{"id": 1, "message": "Hello, SQS!"}' (this is using httpie CLI, install it or covert the same call to curl)

Sample output:

1999-01-01T17:54:30.611000+00:00 1999/01/01/[$LATEST]kjasdf908asdfkajsdf-0uasdkfjasd START RequestId: 2795f527-1078-53e2-9763-ade41a71a60a Version: $LATEST
1999-01-01T17:54:30.615000+00:00 1999/01/01/[$LATEST]kjasdf908asdfkajsdf-0uasdkfjasd 1999-01-01T17:54:30.615Z	2795f527-1078-53e2-9763-ade41a71a60a	INFO	[DEBUG] received this message { id: 1, message: 'Hello, SQS!' }
1999-01-01T17:54:30.619000+00:00 1999/01/01/[$LATEST]kjasdf908asdfkajsdf-0uasdkfjasd END RequestId: 2795f527-1078-53e2-9763-ade41a71a60a
1999-01-01T17:54:30.619000+00:00 1999/01/01/[$LATEST]kjasdf908asdfkajsdf-0uasdkfjasd REPORT RequestId: 2795f527-1078-53e2-9763-ade41a71a60a	Duration: 5.07 ms	Billed Duration: 6 ms	Memory Size: 1024 MB	Max Memory Used: 67 MB

Processing Message Payload

Structure the message as required. The processing logic goes in the handler.js

Environment variables

Serverless uses dotenv to pull in environment variables.

Create a .env with the following and anything else you need:

MY_SUPER_SECRET=ssssshhhhhhh

Permissions

We have set the permissions for SQS:SendMessage to public for this example. Don't do this in prod. Also, take down this service or lock down the permissions once you have done testing out sending messages from the command line.

sqs_with_sls_example's People

Contributors

rujmah avatar

Watchers

 avatar  avatar

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.