Skip to content

Commit d539586

Browse files
authored
Merge branch 'main' into dmelfi/pinning-java-8-version-via-toolchain
2 parents 3bdc951 + ba130c1 commit d539586

13 files changed

Lines changed: 690 additions & 1 deletion

File tree

.github/test-matrix.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"arch": [
3+
{
4+
"runner": "ubuntu-latest",
5+
"label": "x64",
6+
"sam_arch": "x86_64",
7+
"java_suffix": "X64"
8+
},
9+
{
10+
"runner": "ubuntu-24.04-arm",
11+
"label": "arm64",
12+
"sam_arch": "arm64",
13+
"java_suffix": "ARM64"
14+
}
15+
]
16+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# this workflow verifies that the integration test Lambda function builds successfully.
2+
# it does NOT deploy or run the tests (that requires AWS credentials and is done in
3+
# run-integration-test.yml).
4+
5+
name: Build integration tests
6+
7+
on:
8+
push:
9+
branches: [ main ]
10+
paths:
11+
- 'aws-lambda-java-log4j2/**'
12+
- 'aws-lambda-java-core/**'
13+
- 'lambda-integration-tests/**'
14+
pull_request:
15+
branches: [ '*' ]
16+
paths:
17+
- 'aws-lambda-java-log4j2/**'
18+
- 'aws-lambda-java-core/**'
19+
- 'lambda-integration-tests/**'
20+
- '.github/workflows/build-integration-test.yml'
21+
22+
permissions:
23+
contents: read
24+
25+
jobs:
26+
load-matrix:
27+
runs-on: ubuntu-latest
28+
outputs:
29+
matrix: ${{ steps.set.outputs.matrix }}
30+
steps:
31+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
32+
33+
- name: Load test matrix
34+
id: set
35+
run: |
36+
MATRIX=$(jq -c '.' .github/test-matrix.json)
37+
echo "matrix=${MATRIX}" >> "$GITHUB_OUTPUT"
38+
39+
build-arch:
40+
needs: load-matrix
41+
runs-on: ${{ matrix.arch.runner }}
42+
strategy:
43+
fail-fast: false
44+
matrix: ${{ fromJson(needs.load-matrix.outputs.matrix) }}
45+
name: "build (${{ matrix.arch.label }})"
46+
steps:
47+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
48+
49+
- name: Set up JDK
50+
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0
51+
with:
52+
java-version: |
53+
8
54+
21
55+
distribution: corretto
56+
cache: maven
57+
58+
- name: Install core with Maven
59+
run: |
60+
export JAVA_HOME=$JAVA_HOME_8_${{ matrix.arch.java_suffix }}
61+
mvn -B install --file aws-lambda-java-core/pom.xml
62+
63+
- name: Install log4j2 with Maven
64+
run: |
65+
export JAVA_HOME=$JAVA_HOME_8_${{ matrix.arch.java_suffix }}
66+
mvn -B install --file aws-lambda-java-log4j2/pom.xml
67+
68+
# build the integration test function
69+
# this verifies that the function compiles and packages correctly.
70+
# the tests will run in run-integration-test.yml which deploys to AWS.
71+
- name: Package integration test function
72+
run: |
73+
export JAVA_HOME=$JAVA_HOME_21_${{ matrix.arch.java_suffix }}
74+
mvn -B package --file lambda-integration-tests/log4j2-test-function/pom.xml
75+
76+
build:
77+
needs: build-arch
78+
if: always()
79+
runs-on: ubuntu-latest
80+
steps:
81+
- name: Check build results
82+
run: |
83+
if [ "${{ needs.build-arch.result }}" != "success" ]; then
84+
echo "Build failed on one or more architectures"
85+
exit 1
86+
fi
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# this workflow deploys a Lambda function that uses aws-lambda-java-log4j2,
2+
# invokes it, and verifies that logs arrive in CloudWatch.
3+
4+
name: Run integration tests
5+
6+
permissions:
7+
id-token: write
8+
contents: read
9+
10+
on:
11+
workflow_dispatch:
12+
push:
13+
branches: [ main ]
14+
paths:
15+
- 'aws-lambda-java-log4j2/**'
16+
- 'aws-lambda-java-core/**'
17+
- 'lambda-integration-tests/**'
18+
19+
jobs:
20+
load-matrix:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
matrix: ${{ steps.set.outputs.matrix }}
24+
steps:
25+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
26+
27+
- name: Load test matrix
28+
id: set
29+
run: |
30+
MATRIX=$(jq -c '.' .github/test-matrix.json)
31+
echo "matrix=${MATRIX}" >> "$GITHUB_OUTPUT"
32+
33+
run-integration-tests:
34+
needs: load-matrix
35+
# Only run on the main repo, not forks
36+
if: ${{ github.repository_owner == 'aws' }}
37+
runs-on: ${{ matrix.arch.runner }}
38+
strategy:
39+
fail-fast: false
40+
matrix: ${{ fromJson(needs.load-matrix.outputs.matrix) }}
41+
name: "integration-test (${{ matrix.arch.label }})"
42+
concurrency:
43+
group: integration-test-${{ matrix.arch.label }}
44+
cancel-in-progress: false
45+
steps:
46+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
47+
48+
- name: Set up JDK
49+
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0
50+
with:
51+
java-version: |
52+
8
53+
21
54+
distribution: corretto
55+
cache: maven
56+
57+
- name: Install SAM CLI
58+
uses: aws-actions/setup-sam@f84ec7d548307efafe33230528756de3c5841a17 # v2
59+
with:
60+
use-installer: true
61+
62+
- name: Configure AWS credentials
63+
uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7 # v6.0.0
64+
with:
65+
role-to-assume: ${{ secrets.AWS_ROLE_LOG4J2_INTEG_TEST }}
66+
role-session-name: GitHubActionsLog4j2IntegTest
67+
aws-region: ${{ secrets.AWS_REGION_LOG4J2_INTEG_TEST }}
68+
69+
- name: Install core with Maven
70+
run: |
71+
export JAVA_HOME=$JAVA_HOME_8_${{ matrix.arch.java_suffix }}
72+
mvn -B install --file aws-lambda-java-core/pom.xml
73+
74+
- name: Install log4j2 with Maven
75+
run: |
76+
export JAVA_HOME=$JAVA_HOME_8_${{ matrix.arch.java_suffix }}
77+
mvn -B install --file aws-lambda-java-log4j2/pom.xml
78+
79+
- name: Build SAM stack
80+
run: |
81+
export JAVA_HOME=$JAVA_HOME_21_${{ matrix.arch.java_suffix }}
82+
cd lambda-integration-tests && sam build
83+
84+
- name: Validate SAM stack
85+
run: cd lambda-integration-tests && sam validate --lint
86+
87+
- name: Deploy stack
88+
id: deploy_stack
89+
env:
90+
AWS_REGION: ${{ secrets.AWS_REGION_LOG4J2_INTEG_TEST }}
91+
run: |
92+
cd lambda-integration-tests
93+
stackName="aws-lambda-java-log4j2-integ-test-${{ matrix.arch.label }}-$GITHUB_RUN_ID"
94+
echo "STACK_NAME=$stackName" >> "$GITHUB_OUTPUT"
95+
echo "Stack name = $stackName"
96+
sam deploy \
97+
--stack-name "${stackName}" \
98+
--parameter-overrides "ParameterKey=LambdaRole,ParameterValue=${{ secrets.AWS_LAMBDA_ROLE_LOG4J2_INTEG_TEST }} ParameterKey=Architecture,ParameterValue=${{ matrix.arch.sam_arch }}" \
99+
--no-confirm-changeset \
100+
--no-progressbar \
101+
--s3-bucket "${{ secrets.S3_BUCKET_LOG4J2_INTEG_TEST }}" \
102+
--capabilities CAPABILITY_IAM \
103+
2>&1 | tee /tmp/sam-deploy.log | tail -n 20
104+
105+
# Verify stack is in a healthy state
106+
STACK_STATUS=$(aws cloudformation describe-stacks \
107+
--stack-name "${stackName}" \
108+
--region "${AWS_REGION}" \
109+
--query 'Stacks[0].StackStatus' \
110+
--output text 2>&1)
111+
echo "Stack status: $STACK_STATUS"
112+
if [ "$STACK_STATUS" != "CREATE_COMPLETE" ] && [ "$STACK_STATUS" != "UPDATE_COMPLETE" ]; then
113+
echo "FAIL: Stack is not in a healthy state (status: $STACK_STATUS)"
114+
aws cloudformation describe-stack-events \
115+
--stack-name "${stackName}" \
116+
--region "${AWS_REGION}" \
117+
--query 'StackEvents[?ResourceStatus==`CREATE_FAILED` || ResourceStatus==`UPDATE_FAILED`].[LogicalResourceId,ResourceStatusReason]' \
118+
--output table 2>&1 || true
119+
exit 1
120+
fi
121+
122+
LOG4J2_TEST_FUNCTION=$(sam list stack-outputs --stack-name "${stackName}" --output json | jq -r '.[] | select(.OutputKey=="Log4j2TestFunction") | .OutputValue')
123+
echo "LOG4J2_TEST_FUNCTION=$LOG4J2_TEST_FUNCTION" >> "$GITHUB_OUTPUT"
124+
echo "Function name: $LOG4J2_TEST_FUNCTION"
125+
126+
- name: Run integration test
127+
env:
128+
LOG4J2_TEST_FUNCTION: ${{ steps.deploy_stack.outputs.LOG4J2_TEST_FUNCTION }}
129+
AWS_REGION: ${{ secrets.AWS_REGION_LOG4J2_INTEG_TEST }}
130+
run: ./lambda-integration-tests/run-tests.sh
131+
132+
- name: Cleanup
133+
if: always() && steps.deploy_stack.outputs.STACK_NAME
134+
env:
135+
AWS_REGION: ${{ secrets.AWS_REGION_LOG4J2_INTEG_TEST }}
136+
STACK_NAME: ${{ steps.deploy_stack.outputs.STACK_NAME }}
137+
run: |
138+
sam delete --stack-name "${STACK_NAME}" --no-prompts --region "${AWS_REGION}"

aws-lambda-java-log4j2/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Using log4j2 with AWS Lambda
22

3+
**IMPORTANT: The v1.6.3 release contained a regression (see [#612](https://github.com/aws/aws-lambda-java-libs/issues/612)) resulting in missing logs. Please upgrade to v1.6.4 or later. We apologize for the inconvenience.**
4+
35
### 1. Pull in log4j2 dependencies
46

57
Example for Maven pom.xml

aws-lambda-java-log4j2/pom.xml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<maven.compiler.source>1.8</maven.compiler.source>
3636
<maven.compiler.target>1.8</maven.compiler.target>
3737
<log4j.version>2.25.4</log4j.version>
38+
<junit-jupiter.version>5.12.2</junit-jupiter.version>
3839
</properties>
3940

4041
<distributionManagement>
@@ -60,8 +61,50 @@
6061
<artifactId>log4j-api</artifactId>
6162
<version>${log4j.version}</version>
6263
</dependency>
64+
<dependency>
65+
<groupId>org.apache.logging.log4j</groupId>
66+
<artifactId>log4j-layout-template-json</artifactId>
67+
<version>${log4j.version}</version>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.junit.jupiter</groupId>
72+
<artifactId>junit-jupiter-engine</artifactId>
73+
<version>${junit-jupiter.version}</version>
74+
<scope>test</scope>
75+
</dependency>
6376
</dependencies>
6477

78+
<build>
79+
<plugins>
80+
<plugin>
81+
<groupId>org.apache.maven.plugins</groupId>
82+
<artifactId>maven-toolchains-plugin</artifactId>
83+
<version>3.2.0</version>
84+
<configuration>
85+
<toolchains>
86+
<jdk>
87+
<!-- Range matches both "8" (e.g. actions/setup-java)
88+
and "1.8" (legacy / hand-written toolchains). -->
89+
<version>[1.8,9)</version>
90+
</jdk>
91+
</toolchains>
92+
</configuration>
93+
<executions>
94+
<execution>
95+
<goals>
96+
<goal>toolchain</goal>
97+
</goals>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
<plugin>
102+
<artifactId>maven-surefire-plugin</artifactId>
103+
<version>3.5.2</version>
104+
</plugin>
105+
</plugins>
106+
</build>
107+
65108
<profiles>
66109
<profile>
67110
<id>dev</id>
@@ -146,4 +189,4 @@
146189
</build>
147190
</profile>
148191
</profiles>
149-
</project>
192+
</project>

0 commit comments

Comments
 (0)