sam local invoke fails due to inappropriate hostname

Viewed 26

When I run the following simple CDK code locally, it fails. On the other hand, when I built and deployed it, it worked as expected.

from aws_cdk import core as cdk
import aws_cdk.aws_lambda as lambda_
import aws_cdk.aws_apigateway as api_


class HelloWorldStack(cdk.Stack):
    def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        lambda_function = lambda_.Function(
            self, "LambdaFunction",
            function_name="HelloWorldFunction",
            code=lambda_.Code.asset("./lambda"),
            handler="hello_world.handler",
            runtime=lambda_.Runtime.PYTHON_3_8)

        api = api_.LambdaRestApi(
            self, "api",
            handler=lambda_function,
            proxy=False)

        api.root.add_method("GET")


app = cdk.App()
HelloWorldStack(app, "HelloWorldStack")
app.synth()
>sam-beta-cdk local invoke
Invoking hello_world.handler (python3.8)
Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-python3.8:rapid-1.22.0.dev202107140310.

Mounting ...\03_SAM_CDK\cdk\.aws-sam\build\HelloWorldStack\LambdaFunctionBF21E41F as /var/task:ro,delegated inside runtime container

It doesn't seem to work correctly because of requesting the following URL. (xxx.yyy.zzzz is our domain.)

http://localhost.xxx.yyy.zzz:6131/2015-03-31/functions/function/invocations

Does anyone have a solution?

My Environment: OS: Windows 10 Pro docker desktop: v3.5.2 SAM CLI: version 1.22.0.dev202107140310

0 Answers
Related