Skip to content

Commit

Permalink
Add provided.al2 runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mhart committed Aug 12, 2020
1 parent 2d48569 commit 8a91a64
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -336,6 +337,7 @@ These follow the Lambda runtime names:
- `build-dotnetcore2.1`
- `build-dotnetcore3.1`
- `build-provided`
- `build-provided.al2`

## Verifying images

Expand Down
2 changes: 1 addition & 1 deletion base/build-all.sh
Original file line number Diff line number Diff line change
@@ -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}/.."

Expand Down
87 changes: 87 additions & 0 deletions base/dump-providedal2/bootstrap.go
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 8 additions & 0 deletions base/dump-providedal2/go.mod
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions base/dump-providedal2/go.sum
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 1 addition & 1 deletion base/publish-all.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/tag-all.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 4 additions & 0 deletions base/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
27 changes: 27 additions & 0 deletions examples/provided.al2/bootstrap.go
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 8 additions & 0 deletions examples/provided.al2/go.mod
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions examples/provided.al2/go.sum
Original file line number Diff line number Diff line change
@@ -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=
6 changes: 6 additions & 0 deletions provided.al2/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions provided.al2/run/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 8a91a64

Please sign in to comment.