@0xc/serverless-offline-aws-sqs

2.0.3 • Public • Published

builds.sr.ht status License: MIT

serverless-offline-sqs

This Serverless-offline plugin emulates AWS λ and SQS queue on your local machine by using ElasticMQ. To do so, it listens SQS queue and invokes your handlers.

Installation

First, add @0xc/serverless-offline-aws-sqs to your project:

yarn add @0xc/serverless-offline-aws-sqs

Then inside your project's serverless.yml file, add following entry to the plugins section before serverless-offline (and after serverless-webpack if presents): @0xc/serverless-offline-aws-sqs.

plugins:
  - serverless-webpack
  - "@0xc/serverless-offline-aws-sqs"
  - serverless-offline

Configure

Functions

Ths configuration of function of the plugin follows the serverless documentation.

functions:
  mySQSHandler:
    handler: handler.default
    events:
      - sqs:
          queueName: MyQueue
          arn:
            Fn::GetAtt:
              - MyQueue
              - Arn
resources:
  Resources:
    MyQueue:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: MyQueue

Inside your functions you could use a wrapper to switch between local and (aws) production environment.

const AWS = require("aws-sdk");

let options = {};

// connect to local ElasticMQ if running offline
if (process.env.IS_OFFLINE) {
  options = {
    apiVersion: "2012-11-05",
    region: "localhost",
    endpoint: "http://0.0.0.0:9324",
    sslEnabled: false
  };
}

const client = new AWS.SQS(options);

export default client;

Local SQS (ElasticMQ)

The configuration of aws.SQS's client of the plugin is done by defining a custom: serverless-offline-sqs object in your serverless.yml with your specific configuration.

You could use ElasticMQ with the following configuration:

custom:
  "@0xc/serverless-offline-aws-sqs":
    apiVersion: "2012-11-05"
    endpoint: http://0.0.0.0:9324
    region: eu-west-1
    accessKeyId: root
    secretAccessKey: root
    skipCacheInvalidation: false

Before you start your serverless functions you ElasticMQ needs to run.

docker run -it -p 9324:9324 s12v/elasticmq:latest

Queues will be automatically created.

Roadmap

  • install ElasticMQ automatically or start docker automatically

PLEASE HELP ME TO GET THIS DONE! EVERY PR IS WELCOME.

Credits

This is a custom fork from @meuschke/serverless-offline-aws-sqs Project

Dependencies (4)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @0xc/serverless-offline-aws-sqs

    Weekly Downloads

    1

    Version

    2.0.3

    License

    MIT

    Unpacked Size

    15.5 kB

    Total Files

    4

    Last publish

    Collaborators

    • tcarrio