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 serverless-offline-aws-sqs
to your project:
yarn add 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): serverless-offline-aws-sqs
.
plugins: - serverless-webpack - 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 - Arnresources: 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 = ; let options = {}; // connect to local ElasticMQ if running offlineif processenvIS_OFFLINE options = apiVersion: '2012-11-05' region: 'localhost' endpoint: "http://0.0.0.0:9324" sslEnabled: false ; const client = options;
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: 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 CoorpAcademy Project