Skip to content

Commit

Permalink
Merge changes for v1.19 release
Browse files Browse the repository at this point in the history
- Update to Go 1.22 
- Allow user-defined client context
- Refactor test cases
- Add workflow for automated releases
  • Loading branch information
valerena authored May 14, 2024
2 parents 25a2eac + d37e08c commit c99378b
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 157 deletions.
38 changes: 33 additions & 5 deletions .github/workflows/integ-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,44 @@ on:
- develop

jobs:
integ-tests:
go-tests:
runs-on: ubuntu-latest
environment:
name: prod
name: integ-tests
steps:
- uses: actions/checkout@v4
- name: run go tests
run: make tests-with-docker
integ-tests-x86:
runs-on: ubuntu-latest
environment:
name: integ-tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: run integration tests
run: make integ-tests-with-docker-x86-64
integ-tests-arm64:
runs-on: ubuntu-latest
environment:
name: integ-tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: run integration tests
run: make integ-tests-with-docker-arm64
integ-tests-old:
runs-on: ubuntu-latest
environment:
name: integ-tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: allows us to build arm64 images
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- name: run integration tests
run: make integ-tests-with-docker
run: make integ-tests-with-docker-old
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release

on:
workflow_dispatch:
inputs:
releaseVersion:
description: "Version to use for the release."
required: true
default: "X.Y"
releaseBody:
description: "Information about the release"
required: true
default: "New release"
jobs:
Release:
environment: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Build
run: make compile-with-docker-all
- name: Run Integ Tests
run: |
make tests-with-docker
make integ-tests
- name: Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ github.event.inputs.releaseVersion }}
tag_name: v${{ github.event.inputs.releaseVersion }}
body: ${{ github.event.inputs.releaseBody }}
files: |
bin/aws-lambda-rie
bin/aws-lambda-rie-arm64
bin/aws-lambda-rie-x86_64
43 changes: 36 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,64 @@ DESTINATION_old:= bin/${BINARY_NAME}
DESTINATION_x86_64 := bin/${BINARY_NAME}-x86_64
DESTINATION_arm64 := bin/${BINARY_NAME}-arm64

run_in_docker = docker run --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.22 $(1)

compile-with-docker-all:
make ARCH=x86_64 compile-with-docker
make ARCH=arm64 compile-with-docker
make ARCH=old compile-with-docker
$(call run_in_docker, make compile-lambda-linux-all)

compile-lambda-linux-all:
make ARCH=x86_64 compile-lambda-linux
make ARCH=arm64 compile-lambda-linux
make ARCH=old compile-lambda-linux

compile-with-docker:
docker run --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.21 make ARCH=${ARCH} compile-lambda-linux
$(call run_in_docker, make ARCH=${ARCH} compile-lambda-linux)

compile-lambda-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=${GO_ARCH_${ARCH}} go build -buildvcs=false -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -o ${DESTINATION_${ARCH}} ./cmd/aws-lambda-rie

tests-with-docker:
$(call run_in_docker, make tests)

tests:
go test ./...

integ-tests-and-compile: tests
make compile-lambda-linux-all
make integ-tests

integ-tests-with-docker: tests
integ-tests-with-docker: tests-with-docker
make compile-with-docker-all
make integ-tests
integ-tests:

prep-python:
python3 -m venv .venv
.venv/bin/pip install --upgrade pip
.venv/bin/pip install requests parameterized

exec-python-e2e-test:
.venv/bin/python3 test/integration/local_lambda/test_end_to_end.py

integ-tests:
make prep-python
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
make TEST_ARCH=x86_64 TEST_PORT=8002 exec-python-e2e-test
make TEST_ARCH=arm64 TEST_PORT=9002 exec-python-e2e-test
make TEST_ARCH="" TEST_PORT=9052 exec-python-e2e-test

integ-tests-with-docker-x86-64:
make ARCH=x86_64 compile-with-docker
make prep-python
make TEST_ARCH=x86_64 TEST_PORT=8002 exec-python-e2e-test

integ-tests-with-docker-arm64:
make ARCH=arm64 compile-with-docker
make prep-python
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
make TEST_ARCH=arm64 TEST_PORT=9002 exec-python-e2e-test

integ-tests-with-docker-old:
make ARCH=old compile-with-docker
make prep-python
make TEST_ARCH="" TEST_PORT=9052 exec-python-e2e-test

9 changes: 9 additions & 0 deletions cmd/aws-lambda-rie/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"bytes"
"encoding/base64"
"fmt"
"io/ioutil"
"math"
Expand Down Expand Up @@ -81,6 +82,13 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox, bs i
return
}

rawClientContext, err := base64.StdEncoding.DecodeString(r.Header.Get("X-Amz-Client-Context"))
if err != nil {
log.Errorf("Failed to decode X-Amz-Client-Context: %s", err)
w.WriteHeader(500)
return
}

initDuration := ""
inv := GetenvWithDefault("AWS_LAMBDA_FUNCTION_TIMEOUT", "300")
timeoutDuration, _ := time.ParseDuration(inv + "s")
Expand Down Expand Up @@ -114,6 +122,7 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox, bs i
TraceID: r.Header.Get("X-Amzn-Trace-Id"),
LambdaSegmentID: r.Header.Get("X-Amzn-Segment-Id"),
Payload: bytes.NewReader(bodyBytes),
ClientContext: string(rawClientContext),
}
fmt.Println("START RequestId: " + invokePayload.ID + " Version: " + functionVersion)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go.amzn.com

go 1.21
go 1.22

require (
github.com/aws/aws-lambda-go v1.46.0
Expand Down
Loading

0 comments on commit c99378b

Please sign in to comment.