forked from lambci/docker-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for go1.x runtime (lambci#67)
* Add support for go1.x runtime * Add go1.x build image * Add go1.x example * Update README for go1.x
- Loading branch information
Showing
11 changed files
with
599 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"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" | ||
"log" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
func HandleRequest(ctx context.Context, event interface{}) (*s3.PutObjectOutput, error) { | ||
filename := "go1.x.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() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Println("Uploading done!") | ||
|
||
RunShell("ps aux") | ||
|
||
RunShell("xargs --null --max-args=1 < /proc/1/environ") | ||
|
||
for _, a := range os.Args { | ||
fmt.Println(a) | ||
} | ||
pwd, _ := os.Getwd() | ||
fmt.Println(pwd) | ||
for _, e := range os.Environ() { | ||
fmt.Println(e) | ||
} | ||
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) | ||
} | ||
|
||
/* | ||
PATH=/usr/local/bin:/usr/bin/:/bin | ||
LANG=en_US.UTF-8 | ||
TZ=:UTC | ||
LD_LIBRARY_PATH=/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib | ||
_LAMBDA_CONTROL_SOCKET=15 | ||
_LAMBDA_CONSOLE_SOCKET=17 | ||
LAMBDA_TASK_ROOT=/var/task | ||
LAMBDA_RUNTIME_DIR=/var/runtime | ||
_LAMBDA_LOG_FD=24 | ||
_LAMBDA_SB_ID=8 | ||
_LAMBDA_SHARED_MEM_FD=12 | ||
AWS_REGION=us-east-1 | ||
AWS_DEFAULT_REGION=us-east-1 | ||
AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/dump-go1x | ||
AWS_LAMBDA_LOG_STREAM_NAME=2018/01/16/[$LATEST]12d47417179844e3ad55190a93a817d7 | ||
AWS_LAMBDA_FUNCTION_NAME=dump-go1x | ||
AWS_LAMBDA_FUNCTION_MEMORY_SIZE=3008 | ||
AWS_LAMBDA_FUNCTION_VERSION=$LATEST | ||
_AWS_XRAY_DAEMON_ADDRESS=169.254.79.2 | ||
_AWS_XRAY_DAEMON_PORT=2000 | ||
AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000 | ||
AWS_XRAY_CONTEXT_MISSING=LOG_ERROR | ||
_X_AMZN_TRACE_ID=Parent=41bc1aa71e1174a5 | ||
_HANDLER=my_handler | ||
_LAMBDA_RUNTIME_LOAD_TIME=1522376103407 | ||
/var/task | ||
/var/task/my_handler | ||
PATH=/usr/local/bin:/usr/bin/:/bin | ||
LANG=en_US.UTF-8 | ||
TZ=:UTC | ||
LD_LIBRARY_PATH=/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib | ||
_LAMBDA_CONTROL_SOCKET=15 | ||
_LAMBDA_CONSOLE_SOCKET=17 | ||
LAMBDA_TASK_ROOT=/var/task | ||
LAMBDA_RUNTIME_DIR=/var/runtime | ||
_LAMBDA_LOG_FD=24 | ||
_LAMBDA_SB_ID=8 | ||
_LAMBDA_SHARED_MEM_FD=12 | ||
AWS_REGION=us-east-1 | ||
AWS_DEFAULT_REGION=us-east-1 | ||
AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/dump-go1x | ||
AWS_LAMBDA_LOG_STREAM_NAME=2018/01/16/[$LATEST]12d47417179844e3ad55190a93a817d7 | ||
AWS_LAMBDA_FUNCTION_NAME=dump-go1x | ||
AWS_LAMBDA_FUNCTION_MEMORY_SIZE=3008 | ||
AWS_LAMBDA_FUNCTION_VERSION=$LATEST | ||
_AWS_XRAY_DAEMON_ADDRESS=169.254.79.2 | ||
_AWS_XRAY_DAEMON_PORT=2000 | ||
AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000 | ||
AWS_XRAY_CONTEXT_MISSING=LOG_ERROR | ||
_X_AMZN_TRACE_ID=Parent=41bc1aa71e1174a5 | ||
_HANDLER=my_handler | ||
_LAMBDA_RUNTIME_LOAD_TIME=1522376103407 | ||
_LAMBDA_SERVER_PORT=60304 | ||
AWS_ACCESS_KEY= | ||
AWS_ACCESS_KEY_ID= | ||
AWS_SECRET_KEY= | ||
AWS_SECRET_ACCESS_KEY= | ||
AWS_SESSION_TOKEN= | ||
AWS_SECURITY_TOKEN= | ||
context.Background.WithDeadline(2018-01-12 21:16:44.121702432 +0000 UTC [2.981503691s]).WithValue( | ||
&lambdacontext.key{}, | ||
&lambdacontext.LambdaContext{ | ||
AwsRequestID:"e1e762a8-f7dd-11e7-8572-1dc9a2c870b7", | ||
InvokedFunctionArn:"arn:aws:lambda:us-east-1:XXXXXXXXXXXX:function:dump-go1x", | ||
Identity:lambdacontext.CognitoIdentity{CognitoIdentityID:"", CognitoIdentityPoolID:""}, | ||
ClientContext:lambdacontext.ClientContext{Client:lambdacontext.ClientApplication{InstallationID:"", AppTitle:"", AppVersionCode:"", AppPackageName:""}, | ||
Env:map[string]string(nil), | ||
Custom:map[string]string(nil)} | ||
}).WithValue("x-amzn-trace-id", "Root=1-5a5925b8-30ae34971b99966e26b15b1e;Parent=06346dc778d0afed;Sampled=1") | ||
*/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[[constraint]] | ||
name = "github.com/aws/aws-lambda-go" | ||
version = "1.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Compile with: | ||
// docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c 'dep ensure && go build handler.go' | ||
|
||
// Run with: | ||
// docker run --rm -v "$PWD":/var/task lambci/lambda:go1.x 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM lambci/lambda-base:build | ||
|
||
ENV GOLANG_VERSION=1.9.2 \ | ||
GOPATH=/go \ | ||
PATH=/go/bin:/usr/local/go/bin:$PATH | ||
|
||
WORKDIR /go/src/handler | ||
|
||
RUN rm -rf /var/runtime /var/lang && \ | ||
curl https://lambci.s3.amazonaws.com/fs/go1.x.tgz | tar -zx -C / && \ | ||
curl https://dl.google.com/go/go${GOLANG_VERSION}.linux-amd64.tar.gz | tar -zx -C /usr/local && \ | ||
go get github.com/golang/dep/cmd/dep && \ | ||
go install github.com/golang/dep/cmd/dep | ||
|
||
CMD ["dep", "ensure"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM golang:1 | ||
WORKDIR /go/src/github.com/lambci/docker-lambda | ||
RUN curl -sSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64 && chmod +x /usr/local/bin/dep | ||
COPY aws-lambda-mock.go Gopkg.toml Gopkg.lock ./ | ||
RUN dep ensure | ||
RUN GOARCH=amd64 GOOS=linux go build aws-lambda-mock.go | ||
|
||
|
||
FROM lambci/lambda-base | ||
|
||
RUN rm -rf /var/runtime /var/lang && \ | ||
curl https://lambci.s3.amazonaws.com/fs/go1.x.tgz | tar -zx -C / | ||
|
||
COPY --from=0 /go/src/github.com/lambci/docker-lambda/aws-lambda-mock /var/runtime/aws-lambda-go | ||
|
||
USER sbx_user1051 | ||
|
||
ENTRYPOINT ["/var/runtime/aws-lambda-go"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[[constraint]] | ||
name = "github.com/aws/aws-lambda-go" | ||
version = "1.0.1" |
Oops, something went wrong.