From 303175999f533aa358e4d36a1c6597c336b13f60 Mon Sep 17 00:00:00 2001 From: David Beitey Date: Wed, 10 May 2023 10:16:33 +1000 Subject: [PATCH] feat: support Go on provided.al2 runtime This adds support for the current runtime used for Go on AWS. The `go1.x` runtime is EOL as its underlying AMI became EOL on 2020-12-31 and `provided.al2` is its replacement (https://aws.amazon.com/blogs/compute/migrating-aws-lambda-functions-to-al2/). Whilst the AMI is still under extended maintenance support, this extends only until 2023-12-31 (https://aws.amazon.com/blogs/aws/update-on-amazon-linux-ami-end-of-life/). This also ensures that any `vendor/` directories from Go in the runtime tests are ignored. --- src/lambda/handler-runner/HandlerRunner.js | 6 ++- tests/runtimes/go/.gitignore | 1 + tests/runtimes/go/provided.al2/.gitignore | 1 + tests/runtimes/go/provided.al2/go.mod | 5 +++ tests/runtimes/go/provided.al2/go.sum | 22 +++++++++++ tests/runtimes/go/provided.al2/hello/main.go | 19 ++++++++++ .../go/provided.al2/provided.al2.test.js | 38 +++++++++++++++++++ tests/runtimes/go/provided.al2/serverless.yml | 29 ++++++++++++++ 8 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 tests/runtimes/go/.gitignore create mode 100644 tests/runtimes/go/provided.al2/.gitignore create mode 100644 tests/runtimes/go/provided.al2/go.mod create mode 100644 tests/runtimes/go/provided.al2/go.sum create mode 100644 tests/runtimes/go/provided.al2/hello/main.go create mode 100644 tests/runtimes/go/provided.al2/provided.al2.test.js create mode 100644 tests/runtimes/go/provided.al2/serverless.yml diff --git a/src/lambda/handler-runner/HandlerRunner.js b/src/lambda/handler-runner/HandlerRunner.js index e07e6802b..4904e174f 100644 --- a/src/lambda/handler-runner/HandlerRunner.js +++ b/src/lambda/handler-runner/HandlerRunner.js @@ -3,6 +3,7 @@ import { supportedGo, supportedJava, supportedNodejs, + supportedProvided, supportedPython, supportedRuby, unsupportedDockerRuntimes, @@ -66,7 +67,10 @@ export default class HandlerRunner { return new WorkerThreadRunner(this.#funOptions, this.#env) } - if (supportedGo.has(runtime)) { + if ( + supportedGo.has(runtime) || + (supportedProvided.has(runtime) && handler.endsWith('.go')) + ) { const { default: GoRunner } = await import('./go-runner/index.js') return new GoRunner(this.#funOptions, this.#env) diff --git a/tests/runtimes/go/.gitignore b/tests/runtimes/go/.gitignore new file mode 100644 index 000000000..48b8bf907 --- /dev/null +++ b/tests/runtimes/go/.gitignore @@ -0,0 +1 @@ +vendor/ diff --git a/tests/runtimes/go/provided.al2/.gitignore b/tests/runtimes/go/provided.al2/.gitignore new file mode 100644 index 000000000..ba077a403 --- /dev/null +++ b/tests/runtimes/go/provided.al2/.gitignore @@ -0,0 +1 @@ +bin diff --git a/tests/runtimes/go/provided.al2/go.mod b/tests/runtimes/go/provided.al2/go.mod new file mode 100644 index 000000000..0a6e06585 --- /dev/null +++ b/tests/runtimes/go/provided.al2/go.mod @@ -0,0 +1,5 @@ +module serverless-offline-go-provided.al2-test + +go 1.13 + +require github.com/aws/aws-lambda-go v1.28.0 diff --git a/tests/runtimes/go/provided.al2/go.sum b/tests/runtimes/go/provided.al2/go.sum new file mode 100644 index 000000000..2c6fdd886 --- /dev/null +++ b/tests/runtimes/go/provided.al2/go.sum @@ -0,0 +1,22 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/aws/aws-lambda-go v1.28.0 h1:fZiik1PZqW2IyAN4rj+Y0UBaO1IDFlsNo9Zz/XnArK4= +github.com/aws/aws-lambda-go v1.28.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU= +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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +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.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +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= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +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 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tests/runtimes/go/provided.al2/hello/main.go b/tests/runtimes/go/provided.al2/hello/main.go new file mode 100644 index 000000000..bd68173f9 --- /dev/null +++ b/tests/runtimes/go/provided.al2/hello/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "context" + + "github.com/aws/aws-lambda-go/events" + "github.com/aws/aws-lambda-go/lambda" +) + +func Handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { + return events.APIGatewayProxyResponse{ + Body: "{\"message\": \"Hello Go on provided.al2!\"}", + StatusCode: 200, + }, nil +} + +func main() { + lambda.Start(Handler) +} diff --git a/tests/runtimes/go/provided.al2/provided.al2.test.js b/tests/runtimes/go/provided.al2/provided.al2.test.js new file mode 100644 index 000000000..b45819a1b --- /dev/null +++ b/tests/runtimes/go/provided.al2/provided.al2.test.js @@ -0,0 +1,38 @@ +import assert from 'node:assert' +import { env } from 'node:process' +import { join } from 'desm' +import { setup, teardown } from '../../../_testHelpers/index.js' +import { BASE_URL } from '../../../config.js' + +describe('Go via provided.al2 with GoRunner', function desc() { + beforeEach(() => + setup({ + servicePath: join(import.meta.url), + }), + ) + + afterEach(() => teardown()) + + // + ;[ + { + description: 'should work with provided.al2', + expected: { + message: 'Hello Go on provided.al2!', + }, + path: '/dev/hello', + }, + ].forEach(({ description, expected, path }) => { + it(description, async function it() { + if (!env.GO1X_DETECTED) { + this.skip() + } + + const url = new URL(path, BASE_URL) + const response = await fetch(url) + const json = await response.json() + + assert.deepEqual(json, expected) + }) + }) +}) diff --git a/tests/runtimes/go/provided.al2/serverless.yml b/tests/runtimes/go/provided.al2/serverless.yml new file mode 100644 index 000000000..149ebac8d --- /dev/null +++ b/tests/runtimes/go/provided.al2/serverless.yml @@ -0,0 +1,29 @@ +service: docker-go-provided-al2-tests + +configValidationMode: error +deprecationNotificationMode: error + +plugins: + - ../../../../src/index.js + +provider: + architecture: arm64 + deploymentMethod: direct + memorySize: 1024 + name: aws + region: us-east-1 + runtime: provided.al2 + stage: dev + versionFunctions: false + +custom: + serverless-offline: + noTimeout: true + +functions: + hello: + events: + - http: + method: get + path: hello + handler: hello/main.go