serverless-localstack icon indicating copy to clipboard operation
serverless-localstack copied to clipboard

Endpoint url is not shown when using localstack 0.12.5 or 0.12.6

Open svenallers opened this issue 4 years ago • 3 comments

Hi, when I define a serverless endpoint that should be triggered via HTTP, then the serverless deployment does not show the endpoint anymore, besides that the endpoint was deployed successfully. When switching back to localstack 0.12.4 then everything still works fine. I don't know whether this is an issue with the plugin or localstack itself. But even if that is an issue with localstack, I would still not know where the issue would be located in localstack. Maybe you could pinpoint me to where the issue is in localstack if that is the case.

Expected behavior

The HTTP endpoint should be shown after deployment via sls --stage local deploy:

Service Information
service: aws-nodejs
stage: local
region: us-east-1
stack: aws-nodejs-local
resources: 11
api keys:
  None
endpoints:
  http://localhost:4566/restapis/p9hnwqq6f6/local/_user_request_
functions:
  hello: aws-nodejs-local-hello
layers:
  None

Actual behavior

No endpoint is shown after deployment via sls --stage local deploy:

Service Information
service: aws-nodejs
stage: local
region: us-east-1
stack: aws-nodejs-local
resources: 10
api keys:
  None
endpoints:
  None
functions:
  hello: aws-nodejs-local-hello
layers:
  None

Even though the endpoint was successfully deployed and can be used. I verified that by first using the aws cli:

% aws --endpoint-url http://localhost:4566 --region us-east-1 apigateway get-rest-apis 
{
    "items": [
        {
            "id": "nx2wpv1j0g",
            "name": "local-aws-nodejs",
            "createdDate": 1613127132,
            "apiKeySource": "HEADER",
            "endpointConfiguration": {
                "types": [
                    "EDGE"
                ]
            },
            "tags": {}
        }
    ]
}

and calling the endpoint with the api id as one would do usually afterwards:

% curl -i http://localhost:4566/restapis/nx2wpv1j0g/local/_user_request_/hello
HTTP/1.1 200 
content-type: text/html; charset=utf-8
content-length: 9
access-control-allow-origin: *
access-control-allow-methods: HEAD,GET,PUT,POST,DELETE,OPTIONS,PATCH
access-control-allow-headers: authorization,content-type,content-length,content-md5,cache-control,x-amz-content-sha256,x-amz-date,x-amz-security-token,x-amz-user-agent,x-amz-target,x-amz-acl,x-amz-version-id,x-localstack-target,x-amz-tagging
access-control-expose-headers: x-amz-version-id
connection: close
date: Fri, 12 Feb 2021 11:19:20 GMT
server: hypercorn-h11

It works!% 

Example for reproduction

docker-compose.yml

version: "3"

services:
  localstack:
    image: localstack/localstack:0.12.6
    ports:
      - "4566:4566"
    environment:
      SERVICES: "serverless,cloudformation"
      DEBUG: 1
      LAMBDA_EXECUTOR: docker-reuse
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"

serverless.yml

service: aws-nodejs

provider:
  name: aws
  runtime: nodejs10.x
  stage: ${opt:stage, dev}

plugins:
  - serverless-localstack

custom:
  localstack:
    debug: true
    stages: [local]

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: get

handler.js

'use strict';

module.exports.hello = (event, context, callback) => {
  callback(null, {statusCode: 200, body: 'It works!'})
};

svenallers avatar Feb 12 '21 11:02 svenallers

Yes, I have the same problem. My colleague tried to downgrade the version of serverless framework to 2.15.0, and it seemed to work.

Maybe, the serverless version of this plugin is too old, I think.

simonNozaki avatar Mar 20 '21 07:03 simonNozaki

Thanks for reporting @svenallers @simonNozaki . Looks like this is fixed with the latest versions - can you please give it another try with the latest version of the serverless-localstack, and the latest LocalStack Docker image? Thanks

$ sls --version
Framework Core: 2.40.0
Plugin: 4.5.3
SDK: 4.2.2
Components: 3.9.2
$ sls deploy --stage local
...
endpoints:
  http://localhost:4566/restapis/vj1e9rv0hi/local/_user_request_

whummer avatar May 07 '21 18:05 whummer

@whummer

Thanks for your improvement, and I tried to apply the new version!

On my environment, that version worked correctly with API Gateway + Lambda + SQS. First of all, I deployed serverless application to a localstack with Docker. And I called the REST API from Postman locally, and could call it. My serverless environment:

$ sls -v
Framework Core: 2.37.2
Plugin: 4.5.2
SDK: 4.2.2
Components: 3.7.7

So, I think this issue can be closed.

simonNozaki avatar May 11 '21 01:05 simonNozaki

Closing the issue as it seems to be resolved

steffyP avatar Oct 13 '23 10:10 steffyP