Skip to content
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

Add a Runtime API client #298

Merged
merged 10 commits into from Jul 1, 2020
Merged

Add a Runtime API client #298

merged 10 commits into from Jul 1, 2020

Conversation

bmoffatt
Copy link
Collaborator

Description of changes:

This change adds support for using the Lambda Runtime API. The effect of this, is that Lamdba Functions written in go, can be used with both the go1.x, and provided, runtimes.

Why?

  • This is a future-looking change. The Runtime API is where future innovations are going to happen.
  • This makes it easier to implement custom runtimes using go. Got an idea for a custom runtime? You can re-use the AWS Lambda Go programming model to get started

How to try it:

  1. Compile your function as normal.
  2. When creating the .zip, name the binary bootstrap, or place a symlink to your binary named bootstrap within the .zip
  3. When creating a function, choose provided as the runtime
GOOS=linux go build -o bootstrap main.go && zip lambda.zip bootstrap
aws lambda create-function \
   ... \ # iam role, name, memory size
   --zip-file lambda.zip \
   --runtime provided \
   --handler bootstrap # can be any value, the provided runtime ignores this, and always looks for an exe named `bootstrap`

Functions build this way are still compatible with the go1.x runtime. The RPC or the Runtime API mechanism will be detected on startup using environment variables Lambda defines by default.

I've also added a build flag, that allows disabling RPC support, which may result in slightly smaller binary sizes.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@bmoffatt bmoffatt requested a review from carlzogh June 26, 2020 11:27
@codecov-commenter
Copy link

codecov-commenter commented Jun 26, 2020

Codecov Report

Merging #298 into master will increase coverage by 3.05%.
The diff coverage is 75.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #298      +/-   ##
==========================================
+ Coverage   74.60%   77.66%   +3.05%     
==========================================
  Files          13       17       +4     
  Lines         638      761     +123     
==========================================
+ Hits          476      591     +115     
+ Misses        123      116       -7     
- Partials       39       54      +15     
Impacted Files Coverage Δ
lambda/rpc.go 63.63% <63.63%> (ø)
lambda/invoke_loop.go 68.51% <68.51%> (ø)
lambda/entry.go 72.22% <72.72%> (+72.22%) ⬆️
lambda/runtime_api_client.go 77.77% <77.77%> (ø)
lambda/errors.go 95.23% <95.23%> (ø)
lambda/function.go 88.37% <100.00%> (+20.63%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26aa364...8453fa5. Read the comment docs.

lambda/entry.go Show resolved Hide resolved
lambda/entry.go Outdated Show resolved Hide resolved
lambda/invoke_loop_test.go Show resolved Hide resolved
lambda/invoke_loop_test.go Outdated Show resolved Hide resolved
lambda/invoke_loop_test.go Outdated Show resolved Hide resolved
lambda/invoke_loop.go Outdated Show resolved Hide resolved
lambda/runtime_api_client.go Outdated Show resolved Hide resolved
lambda/runtime_api_client.go Outdated Show resolved Hide resolved
dummyPayload := `{"hello": "world"}`

returnsBody := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet || r.URL.Path != "/2018-06-01/runtime/invocation/next" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could re-use apiVersion instead of 2018-06-01

lambda/runtime_api_client_test.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants