diff --git a/.gitignore b/.gitignore index 4a897231..f335be0f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ base/dump-dotnetcore21/bin base/dump-dotnetcore21/obj base/dump-dotnetcore31/bin base/dump-dotnetcore31/obj +base/dump-providedal2/bootstrap +base/dump-providedal2/bootstrap.zip dotnetcore2.0/run/MockBootstraps/bin dotnetcore2.0/run/MockBootstraps/obj dotnetcore2.1/run/MockBootstraps/bin @@ -35,3 +37,5 @@ examples/dotnetcore3.1/pub examples/java/bin examples/java/build examples/go1.x/handler +examples/go1.x/handler +examples/provided.al2/bootstrap diff --git a/README.md b/README.md index 5e0dc318..df924a37 100644 --- a/README.md +++ b/README.md @@ -317,6 +317,7 @@ These follow the Lambda runtime names: - `dotnetcore2.1` - `dotnetcore3.1` - `provided` + - `provided.al2` - `build-nodejs4.3` - `build-nodejs6.10` - `build-nodejs8.10` @@ -336,6 +337,7 @@ These follow the Lambda runtime names: - `build-dotnetcore2.1` - `build-dotnetcore3.1` - `build-provided` + - `build-provided.al2` ## Verifying images diff --git a/base/build-all.sh b/base/build-all.sh index 914a9cff..9a0e6e31 100755 --- a/base/build-all.sh +++ b/base/build-all.sh @@ -1,6 +1,6 @@ #!/bin/bash -RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" +RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 provided.al2 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" TOP_DIR="${PWD}/.." diff --git a/base/dump-providedal2/bootstrap.go b/base/dump-providedal2/bootstrap.go new file mode 100644 index 00000000..a0f1d7b3 --- /dev/null +++ b/base/dump-providedal2/bootstrap.go @@ -0,0 +1,87 @@ +// docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c \ +// 'go mod download && go build -tags lambda.norpc -ldflags="-s -w" bootstrap.go' && \ +// zip bootstrap.zip bootstrap + +package main + +import ( + "context" + "fmt" + "io/ioutil" + "log" + "os" + "os/exec" + "strings" + + "github.com/aws/aws-lambda-go/lambda" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/external" + "github.com/aws/aws-sdk-go-v2/service/s3" +) + +func handleRequest(ctx context.Context, event interface{}) (*s3.PutObjectResponse, error) { + filename := "provided.al2.tgz" + + runShell("tar -cpzf /tmp/" + filename + " --numeric-owner --ignore-failed-read /var/runtime /var/lang") + + fmt.Println("Zipping done! Uploading...") + + cfg, err := external.LoadDefaultAWSConfig() + if err != nil { + log.Fatal(err) + } + + file, err := os.Open("/tmp/" + filename) + if err != nil { + log.Fatal(err) + } + + resp, err := s3.New(cfg).PutObjectRequest(&s3.PutObjectInput{ + ACL: s3.ObjectCannedACLPublicRead, + Body: file, + Bucket: aws.String("lambci"), + Key: aws.String("fs/" + filename), + }).Send(context.Background()) + if err != nil { + log.Fatal(err) + } + + fmt.Println("Uploading done!") + + fmt.Println("Parent env:") + runShell("xargs --null --max-args=1 < /proc/1/environ") + + fmt.Println("Parent cmdline:") + content, err := ioutil.ReadFile("/proc/1/cmdline") + fmt.Println(strings.ReplaceAll(string(content), "\x00", " ")) + + fmt.Println("os.Args:") + for _, a := range os.Args { + fmt.Println(a) + } + + fmt.Println("os.Getwd:") + pwd, _ := os.Getwd() + fmt.Println(pwd) + + fmt.Println("os.Environ:") + for _, e := range os.Environ() { + fmt.Println(e) + } + + fmt.Println("ctx:") + fmt.Println(ctx) + + return resp, nil +} + +func runShell(shellCmd string) { + cmd := exec.Command("sh", "-c", shellCmd) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Run() +} + +func main() { + lambda.Start(handleRequest) +} diff --git a/base/dump-providedal2/go.mod b/base/dump-providedal2/go.mod new file mode 100644 index 00000000..4fc94c95 --- /dev/null +++ b/base/dump-providedal2/go.mod @@ -0,0 +1,8 @@ +module bootstrap + +require ( + github.com/aws/aws-lambda-go v1.19.0 + github.com/aws/aws-sdk-go-v2 v0.24.0 +) + +go 1.15 diff --git a/base/dump-providedal2/go.sum b/base/dump-providedal2/go.sum new file mode 100644 index 00000000..0b1fc768 --- /dev/null +++ b/base/dump-providedal2/go.sum @@ -0,0 +1,26 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/aws/aws-lambda-go v1.19.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU= +github.com/aws/aws-sdk-go-v2 v0.24.0/go.mod h1:2LhT7UgHOXK3UXONKI5OMgIyoQL6zTAw/jwIeX6yqzw= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/base/publish-all.sh b/base/publish-all.sh index e1580b82..9cdc5d45 100755 --- a/base/publish-all.sh +++ b/base/publish-all.sh @@ -1,6 +1,6 @@ #!/bin/bash -RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" +RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 provided.al2 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" echo -n "Enter repository passphrase: " read -s DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE diff --git a/base/tag-all.sh b/base/tag-all.sh index c68f7292..0591bf34 100755 --- a/base/tag-all.sh +++ b/base/tag-all.sh @@ -1,6 +1,6 @@ #!/bin/bash -RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" +RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 provided.al2 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" git tag -f latest diff --git a/base/test-all.sh b/base/test-all.sh index 044cd6ee..c6a40c0e 100755 --- a/base/test-all.sh +++ b/base/test-all.sh @@ -58,6 +58,10 @@ docker run --rm -v "$PWD":/var/task lambci/lambda:go1.x handler '{"Records": []} cd ${EXAMPLES_DIR}/provided docker run --rm -v "$PWD":/var/task lambci/lambda:provided handler '{"some": "event"}' +cd ${EXAMPLES_DIR}/provided.al2 +docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c 'go mod download && go build -tags lambda.norpc bootstrap.go' +docker run --rm -v "$PWD":/var/task lambci/lambda:provided.al2 handler '{"Records": []}' + # To invoke and keep open: # cd ${EXAMPLES_DIR}/ruby # docker run --rm -v $PWD:/var/task -e DOCKER_LAMBDA_STAY_OPEN=1 -p 9001:9001 \ diff --git a/examples/provided.al2/bootstrap.go b/examples/provided.al2/bootstrap.go new file mode 100644 index 00000000..e71e3518 --- /dev/null +++ b/examples/provided.al2/bootstrap.go @@ -0,0 +1,27 @@ +// Compile with: +// docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c 'go mod download && go build -tags lambda.norpc bootstrap.go' + +// Run with: +// docker run --rm -v "$PWD":/var/task lambci/lambda:provided.al2 handler '{"Records": []}' + +package main + +import ( + "context" + "fmt" + + "github.com/aws/aws-lambda-go/events" + "github.com/aws/aws-lambda-go/lambda" +) + +func handleRequest(ctx context.Context, event events.S3Event) (string, error) { + fmt.Println(ctx) + + fmt.Println(event) + + return "Hello World!", nil +} + +func main() { + lambda.Start(handleRequest) +} diff --git a/examples/provided.al2/go.mod b/examples/provided.al2/go.mod new file mode 100644 index 00000000..4fc94c95 --- /dev/null +++ b/examples/provided.al2/go.mod @@ -0,0 +1,8 @@ +module bootstrap + +require ( + github.com/aws/aws-lambda-go v1.19.0 + github.com/aws/aws-sdk-go-v2 v0.24.0 +) + +go 1.15 diff --git a/examples/provided.al2/go.sum b/examples/provided.al2/go.sum new file mode 100644 index 00000000..8da6f30f --- /dev/null +++ b/examples/provided.al2/go.sum @@ -0,0 +1,27 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/aws/aws-lambda-go v1.19.0 h1:Cn28zA8Mic4NpR7p4IlaEW2srI+U3+I7tRqjFMpt/fs= +github.com/aws/aws-lambda-go v1.19.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU= +github.com/aws/aws-sdk-go-v2 v0.24.0/go.mod h1:2LhT7UgHOXK3UXONKI5OMgIyoQL6zTAw/jwIeX6yqzw= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/provided.al2/build/Dockerfile b/provided.al2/build/Dockerfile new file mode 100644 index 00000000..cf5e84ea --- /dev/null +++ b/provided.al2/build/Dockerfile @@ -0,0 +1,6 @@ +FROM lambci/lambda-base-2:build + +# Add these as a separate layer as they get updated frequently +RUN pipx install awscli==1.* && \ + pipx install aws-lambda-builders==1.0.0 && \ + pipx install aws-sam-cli==1.0.0 diff --git a/provided.al2/run/Dockerfile b/provided.al2/run/Dockerfile new file mode 100644 index 00000000..19e39287 --- /dev/null +++ b/provided.al2/run/Dockerfile @@ -0,0 +1,13 @@ +FROM lambci/lambda:provided + + +FROM lambci/lambda-base-2 + +ENV PATH=/var/lang/bin:$PATH \ + LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH + +COPY --from=0 /var/runtime/init /var/runtime/init + +USER sbx_user1051 + +ENTRYPOINT ["/var/runtime/init"]