Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
.git/
.github/
6 changes: 3 additions & 3 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

# Install libcurl dependency
- name: Install dependencies
Expand All @@ -36,7 +36,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -52,7 +52,7 @@ jobs:
cmake -B ${{github.workspace}}/build -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
with:
category: "/language:${{matrix.language}}"

316 changes: 316 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
id-token: write
contents: read

env:
AWS_REGION: ${{ secrets.AWS_REGION }}
FUNCTION_PREFIX: lambda-cpp-integ

jobs:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's define an explicit timeout to avoid waiting for 6h in case of an issue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

unit-test:
runs-on: ${{ matrix.runner }}
timeout-minutes: 10
container: ${{ matrix.container }}
strategy:
fail-fast: false
matrix:
include:
- os: al2023
container: public.ecr.aws/amazonlinux/amazonlinux:2023
runner: ubuntu-latest
- os: al2023-arm
container: public.ecr.aws/amazonlinux/amazonlinux:2023
runner: ubuntu-24.04-arm
- os: ubuntu
container: public.ecr.aws/ubuntu/ubuntu:24.04
runner: ubuntu-latest
- os: alpine
container: public.ecr.aws/docker/library/alpine:3.23
runner: ubuntu-latest
- os: arch
container: public.ecr.aws/docker/library/archlinux:latest
runner: ubuntu-latest

steps:
- name: Install checkout prerequisites
shell: sh
run: |
if command -v dnf > /dev/null 2>&1; then
dnf install -y tar gzip git
elif command -v apk > /dev/null 2>&1; then
apk add --no-cache bash tar git
fi

- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Install dependencies
shell: bash
run: ./ci/integ/install-deps.sh ${{ matrix.os }}

- name: Build and run unit tests
shell: bash
run: ./ci/integ/unit-test.sh ${{ matrix.os }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

~/aws-lambda-cpp
$ ./ci/integ/unit-test.sh al2023
-- Unit tests skipped: Not in GitHub Actions environment
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/moffattb/aws-lambda-cpp/build
[ 62%] Built target aws-lambda-runtime
[100%] Built target lambda-test-fun
Test project /home/moffattb/aws-lambda-cpp/build
No tests were found!!!

can this be resolved in this PR too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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


integration-test-oci:
runs-on: ${{ matrix.build.runner }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
build:
- os: al2023
dockerfile: al2023
runner: ubuntu-latest
lambda_arch: x86_64
- os: al2023-arm
dockerfile: al2023
runner: ubuntu-24.04-arm
lambda_arch: arm64
- os: ubuntu
dockerfile: ubuntu
runner: ubuntu-latest
lambda_arch: x86_64
- os: alpine
dockerfile: alpine
runner: ubuntu-latest
lambda_arch: x86_64
- os: arch
dockerfile: arch
runner: ubuntu-latest
lambda_arch: x86_64
test:
- name: echo_success
handler: echo_success
payload: '{"barbaz":"Hello, Lambda!"}'
assertion: snapshot
- name: echo_unicode
handler: echo_success
payload: '{"UnicodeText":"画像は1000語の価値がある"}'
assertion: snapshot
- name: echo_failure
handler: echo_failure
payload: ""
assertion: snapshot
- name: binary_response
handler: binary_response
payload: ""
assertion: length
- name: crash_backtrace
handler: crash_backtrace
payload: ""
assertion: contains
exclude:
- build:
os: alpine
test:
name: crash_backtrace

steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@254c19bd240aabef8777f48595e9d2d7b972184b # v6.2.1
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@d539f0932e70871a027e9d5a9d8fc38589180a64 # v2.1.6

- name: Ensure ECR repository exists
env:
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
run: |
aws ecr describe-repositories --repository-names "$ECR_REPOSITORY" 2>/dev/null || \
aws ecr create-repository --repository-name "$ECR_REPOSITORY"
aws ecr set-repository-policy --repository-name "$ECR_REPOSITORY" --policy-text '{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "LambdaECRImageRetrievalPolicy",
"Effect": "Allow",
"Principal": { "Service": "lambda.amazonaws.com" },
"Action": ["ecr:BatchGetImage", "ecr:GetDownloadUrlForLayer"]
}
]
}'

- name: Build and push Docker image
env:
ECR_REGISTRY: ${{ steps.ecr-login.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
DOCKERFILE: ${{ matrix.build.dockerfile }}
run: |
docker build \
-f ci/integ/docker/Dockerfile.$DOCKERFILE \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
.
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image_uri=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> "$GITHUB_ENV"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is clear but I have a question. Would moving on the SAM cli help us defining this kind of infrastructure better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This feels like a larger scope change. My inclination is to defer this to a follow-up PR if we feel it's a blocker.


- name: Deploy Lambda function
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-oci-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
uses: aws-actions/aws-lambda-deploy@d496277188b89f0be02d7a2216fc912c0427702a # v1.1.2
with:
function-name: ${{ env.FUNCTION_NAME }}
package-type: Image
image-uri: ${{ env.image_uri }}
architectures: ${{ matrix.build.lambda_arch }}
timeout: 30
role: ${{ secrets.LAMBDA_EXECUTION_ROLE_ARN }}
environment: '{"HANDLER":"${{ matrix.test.handler }}"}'

- name: Invoke and assert
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-oci-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
PAYLOAD: ${{ matrix.test.payload }}
run: ./ci/integ/invoke-and-assert.sh "$FUNCTION_NAME" "$PAYLOAD" "${{ matrix.test.assertion }}" "${{ matrix.test.name }}"

- name: Cleanup Lambda function
if: always()
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-oci-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
run: aws lambda delete-function --function-name "$FUNCTION_NAME" 2>/dev/null || true

- name: Cleanup ECR image
if: always()
env:
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
run: aws ecr batch-delete-image --repository-name "$ECR_REPOSITORY" --image-ids imageTag="$IMAGE_TAG" 2>/dev/null || true

integration-test-zip:
runs-on: ${{ matrix.build.runner }}
timeout-minutes: 10
container: ${{ matrix.build.container }}
strategy:
fail-fast: false
matrix:
build:
- os: al2023
container: public.ecr.aws/amazonlinux/amazonlinux:2023
runner: ubuntu-latest
lambda_arch: x86_64
- os: al2023-arm
container: public.ecr.aws/amazonlinux/amazonlinux:2023
runner: ubuntu-24.04-arm
lambda_arch: arm64
- os: ubuntu
container: public.ecr.aws/ubuntu/ubuntu:24.04
runner: ubuntu-latest
lambda_arch: x86_64
- os: arch
container: public.ecr.aws/docker/library/archlinux:latest
runner: ubuntu-latest
lambda_arch: x86_64
packaging:
- mode: default
id: default
- mode: no-glibc
id: noglibc
test:
- name: echo_success
handler: echo_success
payload: '{"barbaz":"Hello, Lambda!"}'
assertion: snapshot
- name: echo_unicode
handler: echo_success
payload: '{"UnicodeText":"画像は1000語の価値がある"}'
assertion: snapshot
- name: echo_failure
handler: echo_failure
payload: ""
assertion: snapshot
- name: binary_response
handler: binary_response
payload: ""
assertion: length
- name: crash_backtrace
handler: crash_backtrace
payload: ""
assertion: contains
exclude:
- packaging:
mode: no-glibc
build:
os: ubuntu
- packaging:
mode: no-glibc
build:
os: arch

steps:
- name: Install checkout prerequisites
shell: sh
run: |
if command -v dnf > /dev/null 2>&1; then
dnf install -y tar gzip git
elif command -v pacman > /dev/null 2>&1; then
pacman -Syu --noconfirm tar git
fi

- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Install dependencies
shell: bash
run: ./ci/integ/install-deps.sh ${{ matrix.build.os }}

- name: Install AWS CLI
shell: bash
run: |
curl -sSL "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o /tmp/awscli.zip
unzip -q /tmp/awscli.zip -d /tmp
/tmp/aws/install
rm -rf /tmp/awscli.zip /tmp/aws

- name: Build and package zip
shell: bash
run: ./ci/integ/package-zip.sh ${{ matrix.build.os }} ${{ matrix.packaging.mode }}

- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@254c19bd240aabef8777f48595e9d2d7b972184b # v6.2.1
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}

- name: Deploy Lambda function
shell: bash
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-${{ matrix.packaging.id }}-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
run: |
aws lambda create-function \
--function-name "$FUNCTION_NAME" \
--runtime provided.al2023 \
--handler "${{ matrix.test.handler }}" \
--architectures ${{ matrix.build.lambda_arch }} \
--role "${{ secrets.LAMBDA_EXECUTION_ROLE_ARN }}" \
--timeout 30 \
--zip-file fileb://build/tests/resources/lambda-test-fun.zip \
--environment "Variables={HANDLER=${{ matrix.test.handler }}}"

timeout 60 aws lambda wait function-active-v2 --function-name "$FUNCTION_NAME"

- name: Invoke and assert
shell: bash
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-${{ matrix.packaging.id }}-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
PAYLOAD: ${{ matrix.test.payload }}
run: ./ci/integ/invoke-and-assert.sh "$FUNCTION_NAME" "$PAYLOAD" "${{ matrix.test.assertion }}" "${{ matrix.test.name }}"

- name: Cleanup Lambda function
if: always()
shell: bash
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-${{ matrix.packaging.id }}-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
run: aws lambda delete-function --function-name "$FUNCTION_NAME" 2>/dev/null || true
8 changes: 4 additions & 4 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ${{ matrix.arch }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install -y clang-tidy libcurl4-openssl-dev

Expand All @@ -34,7 +34,7 @@ jobs:
build-demo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install -y clang-tidy libcurl4-openssl-dev
Expand All @@ -57,7 +57,7 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Check Formatting
run: ./ci/codebuild/format-check.sh
run: ./ci/format-check.sh
14 changes: 0 additions & 14 deletions ci/README.md

This file was deleted.

Loading
Loading