From 8a1deb0e61c7c826928e20a73a61da42ec54b9ff Mon Sep 17 00:00:00 2001 From: Wing Fung Lau <4760060+hawflau@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:25:36 -0700 Subject: [PATCH] Deprecate provided, go1.x and java8 (#139) * Deprecate provided, go1.x and java8 * update gh build workflow * update Makefile --- .github/workflows/build.yml | 23 ------- Makefile | 9 --- build-image-src/Dockerfile-go1x | 62 ------------------ build-image-src/Dockerfile-provided | 65 ------------------- build-image-src/build_all_images.sh | 6 +- tests/apps/go1.x/hello-world/go.mod | 5 -- tests/apps/go1.x/hello-world/go.sum | 10 --- tests/apps/go1.x/hello-world/main.go | 51 --------------- tests/apps/go1.x/hello-world/main_test.go | 64 ------------------ tests/apps/go1.x/template.yaml | 43 ------------ tests/apps/provided/go1.x/hello-world/go.mod | 5 -- tests/apps/provided/go1.x/hello-world/go.sum | 6 -- tests/apps/provided/go1.x/hello-world/main.go | 51 --------------- .../provided/go1.x/hello-world/main_test.go | 64 ------------------ tests/apps/provided/go1.x/template.yaml | 45 ------------- tests/test_build_images.py | 32 --------- 16 files changed, 1 insertion(+), 540 deletions(-) delete mode 100644 build-image-src/Dockerfile-go1x delete mode 100644 build-image-src/Dockerfile-provided delete mode 100644 tests/apps/go1.x/hello-world/go.mod delete mode 100644 tests/apps/go1.x/hello-world/go.sum delete mode 100644 tests/apps/go1.x/hello-world/main.go delete mode 100644 tests/apps/go1.x/hello-world/main_test.go delete mode 100644 tests/apps/go1.x/template.yaml delete mode 100644 tests/apps/provided/go1.x/hello-world/go.mod delete mode 100644 tests/apps/provided/go1.x/hello-world/go.sum delete mode 100644 tests/apps/provided/go1.x/hello-world/main.go delete mode 100644 tests/apps/provided/go1.x/hello-world/main_test.go delete mode 100644 tests/apps/provided/go1.x/template.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f45240..67951db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,12 +19,10 @@ jobs: if: github.repository_owner == 'aws' && always() runs-on: ubuntu-latest needs: - - build-single-arch - build-multi-arch steps: - name: report-failure if: | - needs.build-single-arch.result != 'success' || needs.build-multi-arch.result != 'success' run: exit 1 - name: report-success @@ -38,27 +36,6 @@ jobs: - id: sam_cli_version run: echo "sam_cli_version=$(curl -s https://pypi.org/pypi/aws-sam-cli/json | jq -r .info.version)" >> $GITHUB_OUTPUT - build-single-arch: - strategy: - fail-fast: false - matrix: - runtime: - - "provided" - - "go1x" - runs-on: ubuntu-latest - needs: [get-sam-cli-version] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.9" - - uses: aws-actions/setup-sam@v2 - with: - use-installer: true - - run: make init - - run: SAM_CLI_VERSION=${{needs.get-sam-cli-version.outputs.sam_cli_version}} RUNTIME=${{matrix.runtime}} make build-single-arch - - run: SAM_CLI_VERSION=${{needs.get-sam-cli-version.outputs.sam_cli_version}} RUNTIME=${{matrix.runtime}} ARCH=x86_64 make test - build-multi-arch: strategy: fail-fast: false diff --git a/Makefile b/Makefile index fe55bc6..fb2264d 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,6 @@ export DOCKER_CONTENT_TRUST := 0 export DOCKER_CLI_EXPERIMENTAL := enabled # image suffix lookup -IS_provided := provided -IS_go1x := go1.x IS_dotnet6 := dotnet6 IS_dotnet7 := dotnet7 IS_dotnet8 := dotnet8 @@ -46,20 +44,13 @@ else @echo "Building runtime $(RUNTIME)" endif -build-single-arch: pre-build - docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) ./build-image-src - build-multi-arch: pre-build docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --platform linux/amd64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=x86_64 --build-arg GO_ARCH=amd64 --build-arg IMAGE_ARCH=x86_64 ./build-image-src docker run --privileged --rm tonistiigi/binfmt --install arm64 docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):arm64 --platform linux/arm64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=aarch64 --build-arg GO_ARCH=arm64 --build-arg IMAGE_ARCH=arm64 ./build-image-src build-x86_64-arch: pre-build -ifeq ($(strip $(RUNTIME)), $(IS_provided)) || ($(strip $(RUNTIME)), $(IS_go1x)) - docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) ./build-image-src -else docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --platform linux/amd64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=x86_64 --build-arg GO_ARCH=amd64 --build-arg IMAGE_ARCH=x86_64 ./build-image-src -endif build-arm64-arch: pre-build docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):arm64 --platform linux/arm64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=aarch64 --build-arg GO_ARCH=arm64 --build-arg IMAGE_ARCH=arm64 ./build-image-src diff --git a/build-image-src/Dockerfile-go1x b/build-image-src/Dockerfile-go1x deleted file mode 100644 index 797edaa..0000000 --- a/build-image-src/Dockerfile-go1x +++ /dev/null @@ -1,62 +0,0 @@ -# reset to the latest emulation image after the raised issue got solved. -# FROM public.ecr.aws/lambda/go:1 -FROM public.ecr.aws/lambda/go:1.2023.08.02.10 - -RUN yum groupinstall -y development && \ - yum install -d1 -y \ - tar \ - gzip \ - unzip \ - python38 \ - jq \ - git \ - grep \ - curl \ - make \ - rsync \ - gcc-c++ \ - binutils \ - procps \ - libgmp3-dev \ - zlib1g-dev \ - liblzma-dev \ - libxslt-devel \ - libmpc-devel \ - && yum clean all - -# Install Go -RUN curl -L https://go.dev/dl/$(curl -L "https://go.dev/VERSION/?m=text" | grep go1.).linux-amd64.tar.gz | tar -zx -C /usr/local -ENV PATH=$PATH:/usr/local/go/bin:/root/go/bin -# Set GOPROXY envvar to avoid using the default proxy.golang.org proxy -ENV GOPROXY=direct - -# Install AWS CLI -RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install && rm awscliv2.zip && rm -rf ./aws - -# Install SAM CLI via native linux installer -ARG SAM_CLI_VERSION -RUN curl -L "https://github.com/aws/aws-sam-cli/releases/download/v$SAM_CLI_VERSION/aws-sam-cli-linux-x86_64.zip" -o "samcli.zip" && \ - unzip samcli.zip -d sam-installation && ./sam-installation/install && \ - rm samcli.zip && rm -rf sam-installation && sam --version - -# Prepare virtualenv for lambda builders -RUN python3 -m venv --without-pip /usr/local/opt/lambda-builders -RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py -RUN /usr/local/opt/lambda-builders/bin/python3 get-pip.py -# Install lambda builders in a dedicated Python virtualenv -RUN AWS_LB_VERSION=$(curl -sSL https://raw.githubusercontent.com/aws/aws-sam-cli/v$SAM_CLI_VERSION/requirements/base.txt | grep aws_lambda_builders | cut -d= -f3) && \ - /usr/local/opt/lambda-builders/bin/pip3 --no-cache-dir install "aws-lambda-builders==$AWS_LB_VERSION" - -ENV PATH=$PATH:/usr/local/opt/lambda-builders/bin - -ENV LANG=en_US.UTF-8 - -# Wheel is required by SAM CLI to build libraries like cryptography. It needs to be installed in the system -# Python for it to be picked up during `sam build` -RUN pip3 install wheel - -COPY ATTRIBUTION.txt / - -# Compatible with initial base image -ENTRYPOINT [] -CMD ["/bin/bash"] diff --git a/build-image-src/Dockerfile-provided b/build-image-src/Dockerfile-provided deleted file mode 100644 index 52c82f8..0000000 --- a/build-image-src/Dockerfile-provided +++ /dev/null @@ -1,65 +0,0 @@ -FROM public.ecr.aws/lambda/provided:alami - -RUN yum groupinstall -y development && \ - yum install -d1 -y \ - tar \ - gzip \ - unzip \ - python38 \ - jq \ - grep \ - curl \ - make \ - rsync \ - gcc-c++ \ - binutils \ - procps \ - libgmp3-dev \ - zlib1g-dev \ - liblzma-dev \ - libxslt-devel \ - libmpc-devel \ - && yum clean all - -# Include build tools for the Function Build image. -# /opt is used for Lambda Layers. To avoid any potential confusion or -# conflict in the future, the build tools are installed in /usr/local/opt - -# Install AWS CLI -RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install && rm awscliv2.zip && rm -rf ./aws - -# Install SAM CLI via native linux installer -ARG SAM_CLI_VERSION -RUN curl -L "https://github.com/aws/aws-sam-cli/releases/download/v$SAM_CLI_VERSION/aws-sam-cli-linux-x86_64.zip" -o "samcli.zip" && \ - unzip samcli.zip -d sam-installation && ./sam-installation/install && \ - rm samcli.zip && rm -rf sam-installation && sam --version - -# Prepare virtualenv for lambda builders -RUN python3 -m venv --without-pip /usr/local/opt/lambda-builders -RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py -RUN /usr/local/opt/lambda-builders/bin/python3 get-pip.py -# Install lambda builders in a dedicated Python virtualenv -RUN AWS_LB_VERSION=$(curl -sSL https://raw.githubusercontent.com/aws/aws-sam-cli/v$SAM_CLI_VERSION/requirements/base.txt | grep aws_lambda_builders | cut -d= -f3) && \ - /usr/local/opt/lambda-builders/bin/pip3 --no-cache-dir install "aws-lambda-builders==$AWS_LB_VERSION" - -ENV PATH=$PATH:/usr/local/opt/lambda-builders/bin - -# Wheel is required by SAM CLI to build libraries like cryptography. It needs to be installed in the system -# Python for it to be picked up during `sam build` -RUN pip3 install wheel - -# Install Go -RUN curl -L https://go.dev/dl/$(curl -L "https://go.dev/VERSION/?m=text" | grep go1.).linux-amd64.tar.gz | tar -zx -C /usr/local -ENV PATH=$PATH:/usr/local/go/bin:/root/go/bin -# Set GOPROXY envvar to avoid using the default proxy.golang.org proxy -ENV GOPROXY=direct - -ENV LANG=en_US.UTF-8 - -ENV PATH=/var/lang/bin:$PATH - -COPY ATTRIBUTION.txt / - -# Compatible with initial base image -ENTRYPOINT [] -CMD ["/bin/bash"] diff --git a/build-image-src/build_all_images.sh b/build-image-src/build_all_images.sh index c40dcd2..f84d26a 100755 --- a/build-image-src/build_all_images.sh +++ b/build-image-src/build_all_images.sh @@ -7,7 +7,7 @@ set -e if [ -z ${SAM_CLI_VERSION+x} ]; then echo "Must set SAM_CLI_VERSION to run this script." - exit -1; + exit 1; else echo "SAM CLI VERSION: $SAM_CLI_VERSION"; fi @@ -16,10 +16,6 @@ fi export DOCKER_CONTENT_TRUST=0 export DOCKER_CLI_EXPERIMENTAL=enabled -# Single arch images -docker build -f Dockerfile-provided -t amazon/aws-sam-cli-build-image-provided:x86_64 --build-arg SAM_CLI_VERSION=$SAM_CLI_VERSION . & -docker build -f Dockerfile-go1x -t amazon/aws-sam-cli-build-image-go1.x:x86_64 --build-arg SAM_CLI_VERSION=$SAM_CLI_VERSION . & -wait # Multi arch images # First build all x86 diff --git a/tests/apps/go1.x/hello-world/go.mod b/tests/apps/go1.x/hello-world/go.mod deleted file mode 100644 index a729d68..0000000 --- a/tests/apps/go1.x/hello-world/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -require github.com/aws/aws-lambda-go v1.45.0 - -module hello-world - -go 1.21.6 diff --git a/tests/apps/go1.x/hello-world/go.sum b/tests/apps/go1.x/hello-world/go.sum deleted file mode 100644 index 2303f92..0000000 --- a/tests/apps/go1.x/hello-world/go.sum +++ /dev/null @@ -1,10 +0,0 @@ -github.com/aws/aws-lambda-go v1.45.0 h1:3xS35Dlc8ffmcwfcKTyqJGiMuL0UDvkQaVUrI5yHycI= -github.com/aws/aws-lambda-go v1.45.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A= -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/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tests/apps/go1.x/hello-world/main.go b/tests/apps/go1.x/hello-world/main.go deleted file mode 100644 index 8c105bd..0000000 --- a/tests/apps/go1.x/hello-world/main.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "io/ioutil" - "net/http" - - "github.com/aws/aws-lambda-go/events" - "github.com/aws/aws-lambda-go/lambda" -) - -var ( - // DefaultHTTPGetAddress Default Address - DefaultHTTPGetAddress = "https://checkip.amazonaws.com" - - // ErrNoIP No IP found in response - ErrNoIP = errors.New("No IP in HTTP response") - - // ErrNon200Response non 200 status code in response - ErrNon200Response = errors.New("Non 200 Response found") -) - -func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { - resp, err := http.Get(DefaultHTTPGetAddress) - if err != nil { - return events.APIGatewayProxyResponse{}, err - } - - if resp.StatusCode != 200 { - return events.APIGatewayProxyResponse{}, ErrNon200Response - } - - ip, err := ioutil.ReadAll(resp.Body) - if err != nil { - return events.APIGatewayProxyResponse{}, err - } - - if len(ip) == 0 { - return events.APIGatewayProxyResponse{}, ErrNoIP - } - - return events.APIGatewayProxyResponse{ - Body: fmt.Sprintf("Hello, %v", string(ip)), - StatusCode: 200, - }, nil -} - -func main() { - lambda.Start(handler) -} diff --git a/tests/apps/go1.x/hello-world/main_test.go b/tests/apps/go1.x/hello-world/main_test.go deleted file mode 100644 index bb1d2a2..0000000 --- a/tests/apps/go1.x/hello-world/main_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "net/http/httptest" - "testing" - - "github.com/aws/aws-lambda-go/events" -) - -func TestHandler(t *testing.T) { - t.Run("Unable to get IP", func(t *testing.T) { - DefaultHTTPGetAddress = "http://127.0.0.1:12345" - - _, err := handler(events.APIGatewayProxyRequest{}) - if err == nil { - t.Fatal("Error failed to trigger with an invalid request") - } - }) - - t.Run("Non 200 Response", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(500) - })) - defer ts.Close() - - DefaultHTTPGetAddress = ts.URL - - _, err := handler(events.APIGatewayProxyRequest{}) - if err != nil && err.Error() != ErrNon200Response.Error() { - t.Fatalf("Error failed to trigger with an invalid HTTP response: %v", err) - } - }) - - t.Run("Unable decode IP", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(500) - })) - defer ts.Close() - - DefaultHTTPGetAddress = ts.URL - - _, err := handler(events.APIGatewayProxyRequest{}) - if err == nil { - t.Fatal("Error failed to trigger with an invalid HTTP response") - } - }) - - t.Run("Successful Request", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(200) - fmt.Fprintf(w, "127.0.0.1") - })) - defer ts.Close() - - DefaultHTTPGetAddress = ts.URL - - _, err := handler(events.APIGatewayProxyRequest{}) - if err != nil { - t.Fatal("Everything should be ok") - } - }) -} diff --git a/tests/apps/go1.x/template.yaml b/tests/apps/go1.x/template.yaml deleted file mode 100644 index e840e27..0000000 --- a/tests/apps/go1.x/template.yaml +++ /dev/null @@ -1,43 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - go - - Sample SAM Template for go - -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 5 - -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Properties: - CodeUri: hello-world/ - Handler: hello-world - Runtime: go1.x - Tracing: Active # https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html - Events: - CatchAll: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: GET - Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object - Variables: - PARAM1: VALUE - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldAPI: - Description: "API Gateway endpoint URL for Prod environment for First Function" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" - HelloWorldFunction: - Description: "First Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn diff --git a/tests/apps/provided/go1.x/hello-world/go.mod b/tests/apps/provided/go1.x/hello-world/go.mod deleted file mode 100644 index 032516a..0000000 --- a/tests/apps/provided/go1.x/hello-world/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -require github.com/aws/aws-lambda-go v1.36.1 - -module hello-world - -go 1.20 diff --git a/tests/apps/provided/go1.x/hello-world/go.sum b/tests/apps/provided/go1.x/hello-world/go.sum deleted file mode 100644 index 15b539f..0000000 --- a/tests/apps/provided/go1.x/hello-world/go.sum +++ /dev/null @@ -1,6 +0,0 @@ -github.com/aws/aws-lambda-go v1.36.1 h1:CJxGkL9uKszIASRDxzcOcLX6juzTLoTKtCIgUGcTjTU= -github.com/aws/aws-lambda-go v1.36.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/tests/apps/provided/go1.x/hello-world/main.go b/tests/apps/provided/go1.x/hello-world/main.go deleted file mode 100644 index 8c105bd..0000000 --- a/tests/apps/provided/go1.x/hello-world/main.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "io/ioutil" - "net/http" - - "github.com/aws/aws-lambda-go/events" - "github.com/aws/aws-lambda-go/lambda" -) - -var ( - // DefaultHTTPGetAddress Default Address - DefaultHTTPGetAddress = "https://checkip.amazonaws.com" - - // ErrNoIP No IP found in response - ErrNoIP = errors.New("No IP in HTTP response") - - // ErrNon200Response non 200 status code in response - ErrNon200Response = errors.New("Non 200 Response found") -) - -func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { - resp, err := http.Get(DefaultHTTPGetAddress) - if err != nil { - return events.APIGatewayProxyResponse{}, err - } - - if resp.StatusCode != 200 { - return events.APIGatewayProxyResponse{}, ErrNon200Response - } - - ip, err := ioutil.ReadAll(resp.Body) - if err != nil { - return events.APIGatewayProxyResponse{}, err - } - - if len(ip) == 0 { - return events.APIGatewayProxyResponse{}, ErrNoIP - } - - return events.APIGatewayProxyResponse{ - Body: fmt.Sprintf("Hello, %v", string(ip)), - StatusCode: 200, - }, nil -} - -func main() { - lambda.Start(handler) -} diff --git a/tests/apps/provided/go1.x/hello-world/main_test.go b/tests/apps/provided/go1.x/hello-world/main_test.go deleted file mode 100644 index bb1d2a2..0000000 --- a/tests/apps/provided/go1.x/hello-world/main_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "net/http/httptest" - "testing" - - "github.com/aws/aws-lambda-go/events" -) - -func TestHandler(t *testing.T) { - t.Run("Unable to get IP", func(t *testing.T) { - DefaultHTTPGetAddress = "http://127.0.0.1:12345" - - _, err := handler(events.APIGatewayProxyRequest{}) - if err == nil { - t.Fatal("Error failed to trigger with an invalid request") - } - }) - - t.Run("Non 200 Response", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(500) - })) - defer ts.Close() - - DefaultHTTPGetAddress = ts.URL - - _, err := handler(events.APIGatewayProxyRequest{}) - if err != nil && err.Error() != ErrNon200Response.Error() { - t.Fatalf("Error failed to trigger with an invalid HTTP response: %v", err) - } - }) - - t.Run("Unable decode IP", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(500) - })) - defer ts.Close() - - DefaultHTTPGetAddress = ts.URL - - _, err := handler(events.APIGatewayProxyRequest{}) - if err == nil { - t.Fatal("Error failed to trigger with an invalid HTTP response") - } - }) - - t.Run("Successful Request", func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(200) - fmt.Fprintf(w, "127.0.0.1") - })) - defer ts.Close() - - DefaultHTTPGetAddress = ts.URL - - _, err := handler(events.APIGatewayProxyRequest{}) - if err != nil { - t.Fatal("Everything should be ok") - } - }) -} diff --git a/tests/apps/provided/go1.x/template.yaml b/tests/apps/provided/go1.x/template.yaml deleted file mode 100644 index a4b26e0..0000000 --- a/tests/apps/provided/go1.x/template.yaml +++ /dev/null @@ -1,45 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - go - - Sample SAM Template for go - -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 5 - -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Metadata: - BuildMethod: go1.x - Properties: - CodeUri: hello-world/ - Handler: hello-world - Runtime: provided - Tracing: Active # https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html - Events: - CatchAll: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: GET - Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object - Variables: - PARAM1: VALUE - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldAPI: - Description: "API Gateway endpoint URL for Prod environment for First Function" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" - HelloWorldFunction: - Description: "First Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn diff --git a/tests/test_build_images.py b/tests/test_build_images.py index 181d9bc..44dd7fc 100644 --- a/tests/test_build_images.py +++ b/tests/test_build_images.py @@ -2,7 +2,6 @@ from tests.build_image_base_test import BuildImageBase, AL2023BasedBuildImageBase - @pytest.mark.java8_al2x86_64 class TestBIJava8AL2(BuildImageBase): __test__ = True @@ -645,37 +644,6 @@ def test_packages(self): self.assertTrue(self.is_package_present("gem")) self.assertTrue(self.is_architecture("aarch64")) -@pytest.mark.go1xx86_64 -class TestBIGo1(BuildImageBase): - __test__ = True - - @classmethod - def setUpClass(cls): - super().setUpClass("go1.x", "Dockerfile-go1x", "mod") - - def test_packages(self): - """ - Test packages specific to this build image - """ - self.assertTrue(self.check_package_output("go version", "go1.")) - self.assertTrue(self.is_package_present("go")) - - -@pytest.mark.providedx86_64 -class TestBIProvided(BuildImageBase): - __test__ = True - - @classmethod - def setUpClass(cls): - super().setUpClass("provided", "Dockerfile-provided") - - def test_packages(self): - """ - Test packages specific to this build image - """ - self.assertTrue(self.check_package_output("go version", "go1.")) - self.assertTrue(self.is_package_present("go")) - @pytest.mark.provided_al2x86_64 class TestBIProvidedAL2(BuildImageBase):