Skip to content

Commit 65ef3fb

Browse files
committed
feat(lmds): Add powertools-lambda-metadata package.
1 parent d8a3e08 commit 65ef3fb

12 files changed

Lines changed: 9113 additions & 0 deletions

File tree

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<module>powertools-e2e-tests</module>
7171
<module>powertools-e2e-tests/handlers</module>
7272
<module>powertools-batch</module>
73+
<module>powertools-lambda-metadata</module>
7374
<module>powertools-parameters/powertools-parameters-ssm</module>
7475
<module>powertools-parameters/powertools-parameters-secrets</module>
7576
<module>powertools-parameters/powertools-parameters-dynamodb</module>

powertools-lambda-metadata/pom.xml

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2023 Amazon.com, Inc. or its affiliates.
4+
~ Licensed under the Apache License, Version 2.0 (the
5+
~ "License"); you may not use this file except in compliance
6+
~ with the License. You may obtain a copy of the License at
7+
~ http://www.apache.org/licenses/LICENSE-2.0
8+
~ Unless required by applicable law or agreed to in writing, software
9+
~ distributed under the License is distributed on an "AS IS" BASIS,
10+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
~ See the License for the specific language governing permissions and
12+
~ limitations under the License.
13+
~
14+
-->
15+
16+
<project xmlns="http://maven.apache.org/POM/4.0.0"
17+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
21+
<artifactId>powertools-lambda-metadata</artifactId>
22+
<packaging>jar</packaging>
23+
24+
<parent>
25+
<artifactId>powertools-parent</artifactId>
26+
<groupId>software.amazon.lambda</groupId>
27+
<version>2.9.0</version>
28+
</parent>
29+
30+
<name>Powertools for AWS Lambda (Java) - Lambda Metadata</name>
31+
<description>
32+
A utility for idiomatic access to the Lambda Metadata Endpoint (LMDS), providing
33+
automatic caching, thread-safe access, and SnapStart support for retrieving
34+
execution environment metadata like Availability Zone ID.
35+
</description>
36+
37+
<dependencies>
38+
<!-- Internal -->
39+
<dependency>
40+
<groupId>software.amazon.lambda</groupId>
41+
<artifactId>powertools-common</artifactId>
42+
</dependency>
43+
44+
<!-- JSON parsing -->
45+
<dependency>
46+
<groupId>com.fasterxml.jackson.core</groupId>
47+
<artifactId>jackson-databind</artifactId>
48+
</dependency>
49+
50+
<!-- CRaC for SnapStart support -->
51+
<dependency>
52+
<groupId>org.crac</groupId>
53+
<artifactId>crac</artifactId>
54+
</dependency>
55+
56+
<!-- Logging -->
57+
<dependency>
58+
<groupId>org.slf4j</groupId>
59+
<artifactId>slf4j-api</artifactId>
60+
</dependency>
61+
62+
<!-- Test dependencies -->
63+
<dependency>
64+
<groupId>org.junit.jupiter</groupId>
65+
<artifactId>junit-jupiter-api</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.junit.jupiter</groupId>
70+
<artifactId>junit-jupiter-engine</artifactId>
71+
<scope>test</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.junit-pioneer</groupId>
75+
<artifactId>junit-pioneer</artifactId>
76+
<scope>test</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.assertj</groupId>
80+
<artifactId>assertj-core</artifactId>
81+
<scope>test</scope>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.mockito</groupId>
85+
<artifactId>mockito-core</artifactId>
86+
<scope>test</scope>
87+
</dependency>
88+
<dependency>
89+
<groupId>org.mockito</groupId>
90+
<artifactId>mockito-junit-jupiter</artifactId>
91+
<scope>test</scope>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.slf4j</groupId>
95+
<artifactId>slf4j-simple</artifactId>
96+
<scope>test</scope>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.wiremock</groupId>
100+
<artifactId>wiremock</artifactId>
101+
<scope>test</scope>
102+
</dependency>
103+
</dependencies>
104+
105+
<build>
106+
<plugins>
107+
<plugin>
108+
<groupId>dev.aspectj</groupId>
109+
<artifactId>aspectj-maven-plugin</artifactId>
110+
<version>${aspectj-maven-plugin.version}</version>
111+
<configuration>
112+
<skip>true</skip>
113+
</configuration>
114+
</plugin>
115+
</plugins>
116+
</build>
117+
118+
<profiles>
119+
<profile>
120+
<id>generate-classesloaded-file</id>
121+
<build>
122+
<plugins>
123+
<plugin>
124+
<groupId>org.apache.maven.plugins</groupId>
125+
<artifactId>maven-surefire-plugin</artifactId>
126+
<configuration>
127+
<argLine>
128+
-Xlog:class+load=info:classesloaded.txt
129+
--add-opens java.base/java.util=ALL-UNNAMED
130+
--add-opens java.base/java.lang=ALL-UNNAMED
131+
</argLine>
132+
</configuration>
133+
</plugin>
134+
</plugins>
135+
</build>
136+
</profile>
137+
<profile>
138+
<id>generate-graalvm-files</id>
139+
<dependencies>
140+
<dependency>
141+
<groupId>org.mockito</groupId>
142+
<artifactId>mockito-subclass</artifactId>
143+
<scope>test</scope>
144+
</dependency>
145+
</dependencies>
146+
<build>
147+
<plugins>
148+
<plugin>
149+
<groupId>org.apache.maven.plugins</groupId>
150+
<artifactId>maven-surefire-plugin</artifactId>
151+
<configuration>
152+
<argLine>
153+
-Dorg.graalvm.nativeimage.imagecode=agent
154+
-agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image/software.amazon.lambda/powertools-lambda-metadata,experimental-class-define-support
155+
--add-opens java.base/java.util=ALL-UNNAMED
156+
--add-opens java.base/java.lang=ALL-UNNAMED
157+
</argLine>
158+
</configuration>
159+
</plugin>
160+
</plugins>
161+
</build>
162+
</profile>
163+
<profile>
164+
<id>graalvm-native</id>
165+
<dependencies>
166+
<dependency>
167+
<groupId>org.mockito</groupId>
168+
<artifactId>mockito-subclass</artifactId>
169+
<scope>test</scope>
170+
</dependency>
171+
</dependencies>
172+
<build>
173+
<plugins>
174+
<plugin>
175+
<groupId>org.graalvm.buildtools</groupId>
176+
<artifactId>native-maven-plugin</artifactId>
177+
<version>0.11.2</version>
178+
<extensions>true</extensions>
179+
<executions>
180+
<execution>
181+
<id>test-native</id>
182+
<goals>
183+
<goal>test</goal>
184+
</goals>
185+
<phase>test</phase>
186+
</execution>
187+
</executions>
188+
<configuration>
189+
<imageName>powertools-lambda-metadata</imageName>
190+
<buildArgs>
191+
<buildArg>--add-opens java.base/java.util=ALL-UNNAMED</buildArg>
192+
<buildArg>--add-opens java.base/java.lang=ALL-UNNAMED</buildArg>
193+
<buildArg>--no-fallback</buildArg>
194+
<buildArg>--verbose</buildArg>
195+
<buildArg>--native-image-info</buildArg>
196+
<buildArg>-H:+UnlockExperimentalVMOptions</buildArg>
197+
<buildArg>-H:+ReportExceptionStackTraces</buildArg>
198+
</buildArgs>
199+
</configuration>
200+
</plugin>
201+
</plugins>
202+
</build>
203+
</profile>
204+
</profiles>
205+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
15+
package software.amazon.lambda.powertools.metadata;
16+
17+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
18+
import com.fasterxml.jackson.annotation.JsonProperty;
19+
20+
/**
21+
* Data class representing Lambda execution environment metadata.
22+
* <p>
23+
* This class is immutable and contains metadata retrieved from the Lambda Metadata Endpoint (LMDS).
24+
* Use {@link LambdaMetadataClient#get()} to obtain an instance.
25+
* </p>
26+
* <p>
27+
* This class is annotated with {@link JsonIgnoreProperties} to ensure forward compatibility.
28+
* </p>
29+
*
30+
* <h2>Example Usage</h2>
31+
* <pre>{@code
32+
* LambdaMetadata metadata = LambdaMetadataClient.get();
33+
* String azId = metadata.getAvailabilityZoneId();
34+
* }</pre>
35+
*
36+
* @see LambdaMetadataClient
37+
*/
38+
@JsonIgnoreProperties(ignoreUnknown = true)
39+
public final class LambdaMetadata {
40+
41+
@JsonProperty("AvailabilityZoneID")
42+
private final String availabilityZoneId;
43+
44+
/**
45+
* Default constructor for Jackson deserialization.
46+
*/
47+
public LambdaMetadata() {
48+
this.availabilityZoneId = null;
49+
}
50+
51+
/**
52+
* Constructor with availability zone ID.
53+
*
54+
* @param availabilityZoneId the availability zone ID
55+
*/
56+
public LambdaMetadata(String availabilityZoneId) {
57+
this.availabilityZoneId = availabilityZoneId;
58+
}
59+
60+
/**
61+
* Returns the Availability Zone ID.
62+
* <p>
63+
* The Availability Zone ID is a unique identifier for the availability zone
64+
* where the Lambda function is executing (e.g., "use1-az1").
65+
* </p>
66+
*
67+
* @return the availability zone ID
68+
*/
69+
public String getAvailabilityZoneId() {
70+
return availabilityZoneId;
71+
}
72+
}

0 commit comments

Comments
 (0)