lifadev / archive_aws-lambda-go-shim

Author your AWS Lambda functions in Go, effectively.

Home Page:https://github.com/eawsy/aws-lambda-go-shim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker Build AWS Lambda function error

vikas027 opened this issue · comments

I am encountering below error on CentOS 7.

docker: Error response from daemon: Failed to initialize logging driver: InvalidParameterException: 1 validation error detected: Value 'eawsy/aws-lambda-go-shim:latest/goofy_jang/86708dc91ade4f34f6a378059f811b228879a35c5809e23cba84a1f72935bd14' at 'logStreamName' failed to satisfy constraint: Member must satisfy regular expression pattern: [^:*]*
	status code: 400, request id: f89491bd-41e2-11e7-a7a4-93e07a8be471.
make: *** [docker] Error 125

Here is the detailed log

# wget -qO- https://github.com/eawsy/aws-lambda-go-shim/raw/master/src/preview.bash | bash
> Pull AWS Lambda build environment from Docker Hub
latest: Pulling from eawsy/aws-lambda-go-shim
Digest: sha256:e7d0182f0703226449446dfbf726dbab4ad35e1960b9a0e1870d80edef34f7ca
Status: Image is up to date for eawsy/aws-lambda-go-shim:latest

> Download AWS Lambda Go dependencies from Github
github.com/eawsy/aws-lambda-go-core (download)

> Download handy Makefile from Github
--2017-05-26 17:14:30--  https://github.com/eawsy/aws-lambda-go-shim/raw/master/src/Makefile.example
Resolving github.com (github.com)... 192.30.255.113, 192.30.255.112
Connecting to github.com (github.com)|192.30.255.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/eawsy/aws-lambda-go-shim/master/src/Makefile.example [following]
--2017-05-26 17:14:31--  https://raw.githubusercontent.com/eawsy/aws-lambda-go-shim/master/src/Makefile.example
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.28.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.28.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2296 (2.2K) [text/plain]
Saving to: ‘Makefile’

100%[====================================================================================================================================================================================================>] 2,296       --.-K/s   in 0s

2017-05-26 17:14:31 (41.4 MB/s) - ‘Makefile’ saved [2296/2296]


> Check AWS Lambda basic execution role

An error occurred (NoSuchEntity) when calling the GetRole operation: Role not found for lambda_basic_execution

> Create AWS Lambda basic execution role
{
    "Role": {
        "AssumeRolePolicyDocument": {
            "Statement": [
                {
                    "Action": "sts:AssumeRole",
                    "Effect": "Allow",
                    "Principal": {
                        "Service": "lambda.amazonaws.com"
                    }
                }
            ]
        },
        "RoleId": "AROAITSGKDWXY7EHC6EFI",
        "CreateDate": "2017-05-26T07:14:31.707Z",
        "RoleName": "lambda_basic_execution",
        "Path": "/",
        "Arn": "arn:aws:iam::XXXXXXXX:role/lambda_basic_execution"
    }
}

> Build AWS Lambda function
docker: Error response from daemon: Failed to initialize logging driver: InvalidParameterException: 1 validation error detected: Value 'eawsy/aws-lambda-go-shim:latest/goofy_jang/86708dc91ade4f34f6a378059f811b228879a35c5809e23cba84a1f72935bd14' at 'logStreamName' failed to satisfy constraint: Member must satisfy regular expression pattern: [^:*]*
	status code: 400, request id: f89491bd-41e2-11e7-a7a4-93e07a8be471.
make: *** [docker] Error 125

This is my go environment.

# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/golang"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build243335846=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

Hi @vikas027,
The problem seems to come from your Docker daemon which is in trouble when trying to run the image.
Can you please double check that you can run other docker images, etc and that your docker daemon works correctly. Run for example docker run hello-world

Thanks for the quick reply @fsenart. I ran the same script on OS X 10.11.2 and everything ran fine.

Not sure what, but there is something not right somewhere.

I cannot doubt my Docker installation/configuration as I am running docker on an AMI which is running lots of Docker production workloads. Here is the output of the command anyways.

# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

Also, I believe -d switch (after base64) is not required in this command. You might wanna update Makefile

> Invoke AWS Lambda function
+ aws lambda invoke --function-name golang-preview --invocation-type RequestResponse --log-type Tail /dev/stderr --query LogResult --output text
+ base64 -d
+ grep -o '[0-9\.]\+ ms'
+ head -1
+ xargs -0 echo -n ' executed in'
base64: invalid option -- d
Usage:	base64 [-dhvD] [-b num] [-i in_file] [-o out_file]
  -h, --help     display this message
  -D, --decode   decodes input
  -b, --break    break encoded string into num character lines
  -i, --input    input file (default: "-" for stdin)
  -o, --output   output file (default: "-" for stdout)

The docker daemon cannot initialize the logging driver due to the name of the log stream. The error says that the log stream name must not have ":" in it but eawsy/aws-lambda-go-shim:latest violate this rule.
It is very weird because I can't imagine that we cannot run an image by precising the tag we need.
What is clear is that the problem is not related to the preview.bash script but to the way the Makefile run the docker image.
Let test something more simple, docker run --rm -it eawsy/aws-lambda-go-shim:latest version. To see if the docker daemon is able to configure the right log stream.

Hmm, yeah Docker is unable to run this container

# docker run -it --rm -it eawsy/aws-lambda-go-shim:latest version
docker: Error response from daemon: Failed to initialize logging driver: InvalidParameterException: 1 validation error detected: Value 'eawsy/aws-lambda-go-shim:latest/dazzling_hamilton/6c9e7bf6c9c39037ee485937aca7c67c76f259b7db36ac3b4b5015d9c32e0d72' at 'logStreamName' failed to satisfy constraint: Member must satisfy regular expression pattern: [^:*]*
	status code: 400, request id: c55a29d0-41f6-11e7-ad58-a10df8a6004e

I have found the issue. We are using awslogs as Docker logging driver. Looks like this image doesn't like this driver (not sure the reason though). I can run the docker command if I specify the log driver along with other switches

# docker run -it --log-driver=json-file --rm -it eawsy/aws-lambda-go-shim:latest version
2017-05-24

Now to fix the issue in the preview.bash script, I have inserted below line at line 52

sed -i 's/docker run/docker run --log-driver=json-file/' Makefile

Overall, I am all set now.

Cheers.

@vikas027 the preview.bash is here only to jump in the project easily. And the Makefile is provided for being fully customized for your needs. So if you need to run the Docker image in your AMI, abandon the preview.bash, download the Makefile and just change anything you want in it. It is only here as an example so moreover than using a sed command, I advocate on creating a custom makefile for your use cases.
Anyway, if you have any other problem in the future, do not hesitate ;) Happy Go on Lambda!

Yeah, I will tweak the Makefile according to my needs. Thanks.