Accessing Lambda URL in Jest when using SamLocal

Hi, I’m using LocalStack with SamLocal so it executes my SAM template in LocalStack and creates our resources.

Now I want to write some integration tests using Jest but unsure on how I can get the function URL into my test to execute the request.

Any help would be appreciated, my function definition is below…

SubmitOrder:
    Type: AWS::Serverless::Function
    Properties:
        FunctionName: submit_order
        Handler: dist/handlers.addOrder
        Runtime: nodejs18.x
        Architectures:
            - x86_64
        MemorySize: 128
        Timeout: 100
        Events:
            Api:
                Type: Api
                Properties:
                    Path: /orders
                    Method: POST

Hi @KeironLowe92,

You should be able to get the URL same as in the AWS sample.

Just change the http://<apiId>.execute-api.us-east-1.amazonaws.com/orders to http://<apiId>.execute-api.localhost.localstack.cloud:4566/<stageId>/<path> as mentioned in our documentation for API Gateway | Docs (localstack.cloud).

1 Like