1

I need to create an integration project which when executed, it should start all aws mock services such as S3, API gateway, SQS, Dynamo db and SSM. We used serverless.com framework for developing lambdas in Node.js that use the above AWS services internally. Also these lambda call another lambda using API Gateway where the X-invocation type is event for asynchronous calls.

Any suggestions on which approach should I choose for running these lambdas locally:

  1. Should i create a serverless project where serverless-offline plugins such as
    • serverless-s3-local
    • serverless-dynamo-local
    • serverless-offline-ssm
    • serverless-offline-dynamodb

So when this project is executed it will run these services on specific port in local machine.

  1. Use SAM Local.

    • For this i need to write a sam template as currently i have used serverless.com framework where there is serverless.yml rather than sam template.
    • There is also serverless-sam plugin to export the serverless.yml to sam template, However, it throws an error for few parts in serverless.yml as for few infra build we use the output of terraform execution in serverless.yml.
    • This terraform is not available for local. So basically i dont have option to use export feature of serverless-sam plugin. I would need to create a separate project that will have sam template containing specification of all dependent AWS service.
  2. Use Python Moto library: https://github.com/spulec/moto#stand-alone-server-mode

Thanks in advance

Amar Panigrahy
  • 75
  • 3
  • 14

1 Answers1

2

It sounds like a good usecase for Localstack

Localstack will spin up a local Docker instance that can act as a local AWS endpoint, and support a lot of services and functionality out of the box.

Positives:

  • Single framework to use, instead of figuring out multiple plugins
  • Language independent - if you decide to move away from Serverless Plugin at some point
  • It supports all the services you mentioned: S3, API gateway, SQS, Dynamo db and SSM
  • It will also be able to execute AWS Lambda's.

Negatives:

  • The AWS Lambdas will be executed in their own, temporary, Docker container. This means that it will not have direct access to the overarching Localstack Docker.
    In other words, executing the Lambda function via Localstack will not be able to call the Localstack API Gateway immediately. For this to work, you have to explicitly set the endpoint-parameter in the AWS SDK to http:/localhost:xxxx (instead of https://apigateway.amazonaws.com)

(See this code as an example, where a Lambda runs in its own Docker container, but needs to access an offline EC2 instance during tests: https://github.com/spulec/moto/blob/master/tests/test_awslambda/test_lambda.py#L55)

Full disclose: I am a Moto collaborator, which is used by Localstack under the hood.

Bert Blommers
  • 1,788
  • 2
  • 13
  • 19