Giter Site home page Giter Site logo

sqs-poc's Introduction

sqs-poc

This is a POC is a rudimentary implementation of the Request-Response Messaging Pattern. It is simply and effort to see how this may work for implementing a TaskEngine, a component responsible for running tasks based on events or on a schedular. For all practical purposes it is little more than an echo service today.

This project uses localstack and Serverless Application Framework for testing and vetting the approach locally prior to pushing to AWS. We can then simply provide the appropirate staget to serverless to deploy to our dev, stage, or prod environments.

Overall Sequence

  1. User sends a request to taskSubmit
  2. Task is then published to sqsTaskQueue a. Confirmation is returned to User
  3. TaskWorker listen to sqsTaskQueue and process the task.
  4. TaskWorker publishes the results of task to sqsTaskQueueResult
  5. User can periodically check for results using taskResult endpoint. The taskResult endpoint which checks sqsTestTsQueueResult for results. If present results are returned or a try agin later is returned.

Getting started

Clone this repo then run npm install from the projects root directory to install the necessary packages from package.json

Environment Requirements

Install serverless:

npm install -g serverless

Make sure you have serverless-localstack and other plugins are installed

npm i serverless-deployment-bucket
npm i serverless-iam-roles-per-function
npm i serverless-localstack
npm i serverless-prune-plugin
npm i serverless-webpack

Deploy the application

Localstack

Creating a CLI Profile for LocalStack

Create a profile for use by localstack by issuing:

aws configure --profile localstack

This will creat a profile name localstack in the ~.aws/config file, which should look something like this:

[profile localstack]
region = us-west-2
output = json

Now this profile can be used with commands to ensure that we are using the right resources. Local stack does not validate credentials, but will complain if no profile is set.

Starting Localstack

In a termial window, go to the root directory of the project and start localstack with docker-compose up.

Starting Serverless

From another termial window, cd to the projets directory, and start serverless. I generally start it like this to see any debugging info in the event there are any issues:

Local Deploy

SLS_DEBUG=3 serverless deploy --stage local --profile localstack --region us-west-2

AWS Dev Deploy

SLS_DEBUG=3 serverless deploy --stage dev 

When the deploy is complete you will be provided the url to the API gateway endpoints. Use these for invoking the lambdas via http. Output from serverless deploy should look something like this:

Service Information
service: task-engine-poc-sqs
stage: local
region: us-west-2
stack: task-engine-poc-sqs-local
resources: 22
api keys:
  None
endpoints:
  http://localhost:4566/restapis/gv7thxca03/local/_user_request_
functions:
  taskSubmit: task-engine-poc-sqs-local-taskSubmit
  jobResult: task-engine-poc-sqs-local-jobResult
  worker: task-engine-poc-sqs-local-worker
layers:
  None

Submit new task

Based on the url's provided under endpoints, submit a task to the Task Engine for processing follwoing the steps below.

Send Message

curl -XPOST -d@messages/send-message.json \
 http://localhost:4566/restapis/nkj1edfh40/local/_user_request_/sqs/taskSubmit

Check for Response

curl http://localhost:4566/restapis/nkj1edfh40/local/_user_request_/sqs/taskResult

Check cloudwatch log

aws --endpoint-url http://localhost:4566 logs tail /aws/lambda/ask-engine-poc-sqs-local-taskSubmit --follow

References

sqs-poc's People

Contributors

joserfjuniorllms avatar

Watchers

 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.