-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing Api Gateway endpoint locally returning No response from invoke container
and Invalid lambda response received
in Dockerised sam app
#2492
Comments
@alliesground SAM CLI is meant to be run from your machine and interact with docker, not run SAM CLI within Docker. My suggestion here is to do that instead of Dockerize. What's the use case on wanting to do this? Why do you need to be running docker within docker? |
I also get this exact error. I will chime in on my use case which may or may not be similar: In my case, I'm using VSCode's Dev Containers, to create an isolated dev environment SAM is running in. My setup is nearly identical, using a volume to expose the host's docker socket, and SAM's Unfortunately, SAM's |
I'm also having the same problem. My use case is exactly the same as @alliesground. I followed the instructions on this post. It makes me think this used to work before. |
I receive same error when trying to hit a lambda spun with 'sam local start-lambda --docker-network host'. It used to work with older version of SAM CLI. I am not doing anything extraordinary, just a basic integration test of a lambda client hitting lambda hosted in SAM CLI |
@gpomykala Your issue is logged here: #2436 (comment) and workarounds here: #2436 (comment) @rbliss @alayor @alliesground |
@jfuss Thank you for your response and links. |
@alayor I am open to ways to make this work if we can find a solution that works across OS. I am not sure if moving to the Just mapping this out:
If in step two, this does publish a port on the machines localhost, then I would assume what you are suggesting could work. Super hacky and seems much easier to just run the CLI on your machine and not have to care about docker at all. Could be a personal preference though. |
@jfuss thanks for your response. It was just an itch of mine to try to dockerize sam-cli especially after reading some articles on the possibilities. Anyways I will move forward with your advice and run CLI on the host machine and maybe try to connect it with other tech stacks running in the container. |
I was able to get SAM local invoke to work inside Dev Container by replacing hardcoded https://github.com/aws/aws-sam-cli/blob/develop/samcli/local/docker/container.py#L41 with @jfuss I'm running this on macOS, AFAIK this won't work on linux out of the box due to docker/for-linux#264, but a SAM CLI option to specify host would be nice. |
Given that SAM CLI is launching a container to run SAM template, would it make sense to consider documenting how to launch the image via Docker Compose (or similar tool)? Probably ought to explain why some of us want to run SAM under Docker (regardless if it's a good idea, possible, etc.) One of the nice things about developing with Docker is that it helps to avoid workstation bloat and conflicts by, for example, having to install yet another package manager (i.e. Homebrew); which, in turn, steps on our environment's default Python version. This is not to pick on Homebrew, it's probably great; although like many tools of its ilk it is much easier to install than to remove when you no longer need it (like having to manually edit ~/bashrc). At the very least, let Python developers know in the docs there's the option of running On a side note, I tried ilyasotkov's workaround/hack in Linux and it didn't work for me. For anybody interested, here's the Dockerfile I set up:
And the entrypoint.sh...
|
Another common use case for dockerizing sam: CI pipelines. Like @jasonterando said, it's a pain to maintain packages/tools installed on build agents. Different teams need their tools in particular ways. It's more like dependencies for your projects. The tools break over time, so you need to keep your setup predictable. That's what docker provides. If it's "not a good idea" to use sam within docker, then I run out of ideas to make my CI pipeline stable over long period of time. I can't trust my scripts/code to still work 1 year from now, after countless patching/upgrading of the build agents. Not to mention that normally it's not easy to tweak infrastructure setups within big corporates, it's a long and risky process. Sometimes impossible (e.g. they refuse to install arbitrary software on agents, because they gave you docker already). |
@jfuss Doesn't the presence of
So remote Docker hosts are already partially supported. |
This works around the same error as aws#2492 See https://circleci.com/docs/2.0/building-docker-images/
This works around the same error as aws#2492 See https://circleci.com/docs/2.0/building-docker-images/
This works around the same error as aws#2492 See https://circleci.com/docs/2.0/building-docker-images/
Adding the If I read the comments correctly, it sounds like the primary use-case here is to use the SAM CLI inside a Dockerized development environment, a-la VSCode remote. Is that correct? Could you tell us a little bit more about the rest of the environment setup (OS, IDE, etc) so that we can make sure we plan accordingly and have the right conversation on our side. Let us take this away and think about it for a bit. |
This works around the same error as aws#2492 See https://circleci.com/docs/2.0/building-docker-images/
For DevOps, we like to launch containers that execute build and then unit and integration testing. It keeps us from having to clutter up our CI/CD server with external dependencies for which we have to keep track of for updates, etc. For example, I can deploy a PHP application which runs composer install and PHPUnit without having to have PHP, composer, etc. installed on the CI/CD server, and have to worry about keeping them up-to-date. In the case of SAM, it'd be nice to start off with a base image of AWS SAM CLI, add in TypeScript, do my testing and then build by deployment all from a container, without having to deal with installing dependencies on my CI/CD server. For development purposes, it would be slick to be able to set up a Docker Compose configuration that launches the SAM-configured service with accompanying dependencies (like localstack for simulating communication with Amazon resources like S3 and Kinesis), mocked external services, etc.. Using Docker Compose for this is largely OS-agnostic, without having to install everything on the developer's machine. Alternatively I can stand up Bash, PowerShell, etc. scripts to launch and integrate things, but it's more clunky, and in the case of installing the SAM CLI, may involve installing things like Homebrew which make changes to the developer's Python environment. |
I used the docker-in-docker setup to be able to attach VS Code's debugger to a SAM CLI-managed container when using VS Code dev containers. This repo demonstrates this (with the above https://github.com/ilyasotkov/vscode-devcontainer-aws-sam-local I'm running this on a macOS machine but it could equally be Ubuntu or Windows as long as it has Docker Desktop installed. |
downgrade to 1.12.0. works |
Thanks for looking into this @sapessi. Have you got any updates you might be able to share on progress? I'd like to echo the points @jasonterando made on the use-cases for this functionality. Essentially, we'd like to be able to run the CLI via docker to allow:
|
I got the same error as the description of the issue. I have
|
Other than downgrading to 1.12.0, is there a workaround for newer versions when not doing anything network related? I'm keen to try to use warm containers in the newer versions to profile performance without the Java classloader penalties, but I'm only doing I would assume this would be a more widespread issue if it didn't work for anyone, so would there be something about my environment that would cause this? I'm using Docker Toolbox (unfortunately I can't use Desktop due to Hyper-V issues) which means I'm stuck with Docker 19.03. As I'm on Windows, this is all running in a VirtualBox VM and I'm invoking SAM on the Windows side. I've not done anything to the network configuration with regards to Docker, but creating a network with |
I have a working compose setup where in the function hackLocalhostIp {
local localhost_ip="$(getent hosts host.docker.internal | awk '{ print $1 }')"
# Docker mounts /etc/hosts so we can't update the file in place with sed
cp /etc/hosts tmpfile
sed "/^127.0.0.1/ s/.*/$localhost_ip\tlocalhost/g" < tmpfile > /etc/hosts
rm tmpfile
} |
I have similar problem calling lambda locally:
And can't see output at all: Lambda has been written in nodejs14.x.
I tried to downgrade to version 1.12.0 but got a message that node14.x is not supported. |
Thank you all for the feedback. I have added this to our backlog and we'll post updates here as we prioritize it. |
I fixed this like this - Essentially, make sure your SAM local and database are running on the same Docker network that it not host. > sam --version
SAM CLI, version 1.20.0 version: '3.5'
services:
postgres:
image: postgres:10.12
...
networks:
- api
networks:
api: Use
|
I'm trying the Is there an option so the ports are not bound to localhost inside the container? This is the command I'm using sam local start-lambda \
-t template.yaml \
--profile sandbox \
--region us-east-1 \
--env-vars .envs.json \
--host 0.0.0.0 \
--parameter-overrides Environment=sandbox \
--container-host 192.168.99.102 \
--warm-containers LAZY \
--skip-pull-image This started failing after upgrading to 1.8 and newer versions. |
Ok, I have new information on the issue. aws-sam-cli/samcli/local/docker/container.py Lines 153 to 158 in 86f88cb
Can you see how '127.0.0.1' is hardcoded on the code? Why? If I remove the |
@kstro21 Hi we hardcoded I'm trying to reproduce your issue. I have a few questions. You have SAM CLI and your project on your local host while Docker engine is running on a remote host right? Does Docker have access to your local SAM files and how is your Docker file sharing setup? |
Hey, @xazhao, yes, I have SAM CLI and my project on my local computer, and the Docker engine is running on a remote host, Docker has access to my SAM files through a mounted remoted directory. But if you are in Linux, you can easily reproduce it using what @jamesorlakin is using, Docker Toolbox which will run the Docker containers inside a VirtualBox Virtual Machine. Let me know if that helps. |
@xazhao In our setup we have the following:
The docker host is remote from the perspective of the build container. I slightly modified sam cli in our build container image to get it to work currently:
|
@rv2673 Using
|
For those who are wondering how to downgrade to 1.12.0 – this worked for me:
|
@xazhao, thanks, it works. What's the difference between sam local start-api \
-t template.yaml \
--region us-east-1 \
--env-vars .envs.json \
--parameter-overrides Environment=sandbox \
--container-host 192.168.99.102 \
--container-host-interface 192.168.99.102 \
--warm-containers LAZY \
--skip-pull-image As you can see, both options have the same value. |
@kstro21 In your case, yes these two options have the same value. |
@xazhao Sorry was off for a few days. But just tested it, and it works great. |
@alexdrans This worked for me. Thanks! For anyone who finds this: I replaced |
Is there a resolution to this issue?
|
I had the same issue. |
That was a pretty good tip but the issue is still unresolved:
Navigating to the url with the proper endpoint: This is a mess. I just want to have an environment to test my lambdas before deploying them. |
I am having the same issue as @kingram6865 |
hey friends above that were having the "Internal Server error" response, I think I had the same thing come up, maybe this would help? I started off having the "empty response" issue no matter what I tried. After a lot of trial and error, eventually I landed on the below combination of things: This here is the command I am using: The combination of the |
Description:
I'm dockerising sam app. When accessing api endpoint for HelloWorld locally, it responds with
No response from invoke container for HelloWorldFunction
andInvalid lambda response received: Lambda response must be valid json
.It works fine whithout dockerisation.
Steps to reproduce:
Dockerfile
docker-compose.yml
Entrypoint.sh
hello_world/app.rb
Observed result:
Expected result:
Json output on browser {message: "hello world"}
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: 1.15.0Homebrew
: VERSION="2.6.2"docker
: VERSION="19.03.8"Add --debug flag to command you are running
The text was updated successfully, but these errors were encountered: