LocalStack Logs

View logs from LocalStack function invocations in Epsagon.

Configure LocalStack starting by raising the image with this docker-compose.yaml format:

version: '3.9'

services:
  localstack:
    image: localstack/localstack:0.12.10
    environment:
      - SERVICES=${SERVICES- }
      - DATA_DIR=${DATA_DIR- }
      - PORT_WEB_UI=8080
      - START_WEB=0
      - LAMBDA_REMOTE_DOCKER=true
      - LAMBDA_EXECUTOR=docker
      - LAMBDA_REMOVE_CONTAINERS=true
      - DOCKER_HOST=unix:///var/run/docker.sock
      - LAMBDA_DOCKER_NETWORK=localstack-net
      - KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
      - LS_LOG=info
      - DEBUG=1
      - TMPDIR=./tmp/localstack
      - HOST_TMP_FOLDER=${TMPDIR}
    ports:
      - '4566-4583:4566-4583'
      - "${PORT_WEB_UI-4666}:${PORT_WEB_UI-8080}"
      - "8080:8080"
    volumes:
      - "${TEMPDIR:-/tmp/localstack}:/temp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"

networks:
  localstack-net:
    name: localstack-net

The LAMBDA_EXECUTOR environment variable must be set to docker in order to work.

Next, bring up the images locally.

$ docker compose up

And set up the serverless environment if not already existing.

$ sls create --template RUNTIME

Be sure to format your serverless.yaml to match localstack configurations.

service: SERVICE

provider:
  name: aws
  runtime: RUNTIME
  stage: ${opt:stage,'local'}
  region: us-east-1

plugins:
  - serverless-localstack

custom:
  stage: ${self:provider.stage}
  localstack:
    hostname:
      local: http://localhost
      staging: remote
    debug: true
    stages:
      - local
      - test
    host: ${self:custom.localstack.hostname.${self:provider.stage}}
    endpoints:
      APIGateway: ${self:custom.localstack.hostname.${self:provider.stage}}:4566
      DynamoDB: ${self:custom.localstack.hostname.${self:provider.stage}}:4566
      SQS: ${self:custom.localstack.hostname.${self:provider.stage}}:4566
      Lambda: ${self:custom.localstack.hostname.${self:provider.stage}}:4566
      CloudWatch: ${self:custom.localstack.hostname.${self:provider.stage}}:4566
      CloudWatchLogs: ${self:custom.localstack.hostname.${self:provider.stage}}:4566
      CloudFormation: ${self:custom.localstack.hostname.${self:provider.stage}}:4566

functions:
  main:
    handler: handler.main

Use Either Epsagon's Serverless Plugin or use the agent's library to trace your serverless functions.

Now deploy your functions to the local containers.

$ serverless deploy --stage local

And invoke your traced, deployed function.

$ serverless invoke -f HANDLER --stage local

Be sure not to use "invoke local". You want to invoke only the deployed version.

Upon opening a trace, Epsagon automatically recognizes the trace as coming from LocalStack, and will open as the following. The Logs button will indicate the LocalStack recognition.

And opening the logs works as normal: click Show LocalStack Logs.

Configurations

If LocalStack is not running on the default port 4566, you will likely encounter an Error

POST http://localhost:3002/ net::ERR_CONNECTION_REFUSED.
To which you can change the endpoint by opening the Browser's DevTools console and entering:

localStorage.setItem('localstack_endpoint', 'http://localhost:NEW_PORT')

And refreshing with Ctrl/Cmd + R.

If LocalStack is running correctly, but an error message of The specified log group does not exist shows, then the serverless function needs to be deployed and invoked again in order to find the correct LogGroup in your local CloudWatch.

$ serverless deploy --stage local
$ serverless invoke -f HANDLER --stage local

Support

Reach out to us through our in-app Live Support, over Slack, or feel free to email [email protected] We're always happy to help :)


Did this page help you?