Skip to content

Commit 42ae2f6

Browse files
committed
Merge remote-tracking branch 'origin/main' into example-docs
2 parents 97c6dea + 39ba43b commit 42ae2f6

File tree

37 files changed

+794
-39
lines changed

37 files changed

+794
-39
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ This project follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) fo
88

99
## [Unreleased]
1010

11+
## [1.16.1] - 2023-07-19
12+
13+
* Fix: idempotency timeout bug (#1285) by @scottgerring
14+
* Fix: ParamManager cannot provide default SSM & Secrets providers (#1282) by @jeromevdl
15+
* Fix: Handle batch failures in FIFO queues correctly (#1183) by @scottgerring
16+
* Deps: Bump third party dependencies to the latest versions.
17+
18+
1119
## [1.16.0] - 2023-06-29
1220

1321

README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,27 @@ Powertools for AWS Lambda (Java) is available in Maven Central. You can use your
2020
<dependency>
2121
<groupId>software.amazon.lambda</groupId>
2222
<artifactId>powertools-tracing</artifactId>
23-
<version>1.16.0</version>
23+
<version>1.16.1</version>
2424
</dependency>
2525
<dependency>
2626
<groupId>software.amazon.lambda</groupId>
2727
<artifactId>powertools-logging</artifactId>
28-
<version>1.16.0</version>
28+
<version>1.16.1</version>
2929
</dependency>
3030
<dependency>
3131
<groupId>software.amazon.lambda</groupId>
3232
<artifactId>powertools-metrics</artifactId>
33-
<version>1.16.0</version>
33+
<version>1.16.1</version>
3434
</dependency>
3535
...
3636
</dependencies>
3737
```
3838

39-
And configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lambda-powertools-java aspects into your project:
39+
Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lambda-powertools-java aspects into your project. A different configuration is needed for projects on Java 8.
4040

41-
For Java 11+, use the following:
41+
<details>
42+
<summary><b>Maven - Java 11 and newer</b></summary>
43+
4244
```xml
4345
<build>
4446
<plugins>
@@ -78,8 +80,11 @@ For Java 11+, use the following:
7880
</plugins>
7981
</build>
8082
```
83+
</details>
8184

82-
For Java 8, use the following:
85+
<details>
86+
<summary><b>Maven - Java 8</b></summary>
87+
8388
```xml
8489
<build>
8590
<plugins>
@@ -119,11 +124,12 @@ For Java 8, use the following:
119124
</plugins>
120125
</build>
121126
```
122-
#### gradle
127+
</details>
123128

124-
For Java 11+:
129+
<details>
130+
<summary><b>Gradle - Java 11+</b></summary>
125131

126-
```groovy
132+
```groovy
127133
plugins {
128134
id 'java'
129135
id 'io.freefair.aspectj.post-compile-weaving' version '8.1.0'
@@ -141,11 +147,13 @@ For Java 11+:
141147
142148
sourceCompatibility = 11
143149
targetCompatibility = 11
144-
```
150+
```
151+
</details>
145152

146-
For Java8:
153+
<details>
154+
<summary><b>Gradle - Java 8</b></summary>
147155

148-
```groovy
156+
```groovy
149157
plugins {
150158
id 'java'
151159
id 'io.freefair.aspectj.post-compile-weaving' version '6.6.3'
@@ -163,10 +171,10 @@ For Java8:
163171
164172
sourceCompatibility = 1.8
165173
targetCompatibility = 1.8
166-
```
167-
174+
```
175+
</details>
168176

169-
## Example
177+
## Examples
170178

171179
See the **[examples](examples)** directory for example projects showcasing usage of different utilities.
172180

examples/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.amazon.lambda</groupId>
88
<artifactId>powertools-examples</artifactId>
9-
<version>1.17.0-SNAPSHOT</version>
9+
<version>1.16.1</version>
1010
<packaging>pom</packaging>
1111

1212
<name>Powertools for AWS Lambda (Java) library Examples</name>
@@ -21,6 +21,7 @@
2121
<module>powertools-examples-serialization</module>
2222
<module>powertools-examples-sqs</module>
2323
<module>powertools-examples-validation</module>
24+
<module>powertools-examples-cloudformation</module>
2425
</modules>
2526

2627
<!-- Don't deploy the examples -->
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Cloudformation Custom Resource Example
2+
3+
This project contains an example of Lambda function using the CloudFormation module of Powertools for AWS Lambda in Java. For more information on this module, please refer to the [documentation](https://awslabs.github.io/aws-lambda-powertools-java/utilities/custom_resources/).
4+
5+
## Deploy the sample application
6+
7+
This sample can be used either with the Serverless Application Model (SAM) or with CDK.
8+
9+
### Deploy with SAM CLI
10+
To use the SAM CLI, you need the following tools.
11+
12+
* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
13+
* Java 8 - [Install Java 8](https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/downloads-list.html)
14+
* Maven - [Install Maven](https://maven.apache.org/install.html)
15+
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)
16+
17+
To build and deploy this application for the first time, run the following in your shell:
18+
19+
```bash
20+
cd infra/sam
21+
sam build
22+
sam deploy --guided --parameter-overrides BucketNameParam=my-unique-bucket-20230717
23+
```
24+
25+
### Deploy with CDK
26+
To use CDK you need the following tools.
27+
28+
* CDK - [Install CDK](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html)
29+
* Java 8 - [Install Java 8](https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/downloads-list.html)
30+
* Maven - [Install Maven](https://maven.apache.org/install.html)
31+
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)
32+
33+
To build and deploy this application for the first time, run the following in your shell:
34+
35+
```bash
36+
cd infra/cdk
37+
mvn package
38+
cdk synth
39+
cdk deploy -c BucketNameParam=my-unique-bucket-20230718
40+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.classpath.txt
2+
target
3+
.classpath
4+
.project
5+
.idea
6+
.settings
7+
.vscode
8+
*.iml
9+
10+
# CDK asset staging directory
11+
.cdk.staging
12+
cdk.out
13+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"app": "mvn -e -q compile exec:java",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"target",
11+
"pom.xml",
12+
"src/test"
13+
]
14+
},
15+
"context": {
16+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
17+
"@aws-cdk/core:checkSecretUsage": true,
18+
"@aws-cdk/core:target-partitions": [
19+
"aws",
20+
"aws-cn"
21+
],
22+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
23+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
24+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
25+
"@aws-cdk/aws-iam:minimizePolicies": true,
26+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
27+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
28+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
29+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
30+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
31+
"@aws-cdk/core:enablePartitionLiterals": true,
32+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
33+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
34+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
35+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true
36+
}
37+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.myorg</groupId>
7+
<artifactId>powertools-examples-cloudformation-cdk</artifactId>
8+
<version>0.1</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<cdk.version>2.59.0</cdk.version>
13+
<constructs.version>[10.0.0,11.0.0)</constructs.version>
14+
</properties>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-compiler-plugin</artifactId>
21+
<version>3.8.1</version>
22+
<configuration>
23+
<source>8</source>
24+
<target>8</target>
25+
</configuration>
26+
</plugin>
27+
28+
<plugin>
29+
<groupId>org.codehaus.mojo</groupId>
30+
<artifactId>exec-maven-plugin</artifactId>
31+
<version>3.0.0</version>
32+
<configuration>
33+
<mainClass>com.myorg.PowertoolsExamplesCloudformationCdkApp</mainClass>
34+
</configuration>
35+
</plugin>
36+
</plugins>
37+
</build>
38+
39+
<dependencies>
40+
<!-- AWS Cloud Development Kit -->
41+
<dependency>
42+
<groupId>software.amazon.awscdk</groupId>
43+
<artifactId>aws-cdk-lib</artifactId>
44+
<version>${cdk.version}</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>software.constructs</groupId>
49+
<artifactId>constructs</artifactId>
50+
<version>${constructs.version}</version>
51+
</dependency>
52+
</dependencies>
53+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.myorg;
2+
3+
import software.amazon.awscdk.App;
4+
import software.amazon.awscdk.StackProps;
5+
6+
public class PowertoolsExamplesCloudformationCdkApp {
7+
public static void main(final String[] args) {
8+
App app = new App();
9+
10+
new PowertoolsExamplesCloudformationCdkStack(app, "PowertoolsExamplesCloudformationCdkStack", StackProps.builder()
11+
.build());
12+
13+
app.synth();
14+
}
15+
}
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.myorg;
2+
3+
import software.amazon.awscdk.Stack;
4+
import software.amazon.awscdk.*;
5+
import software.amazon.awscdk.services.iam.Effect;
6+
import software.amazon.awscdk.services.iam.PolicyStatement;
7+
import software.amazon.awscdk.services.iam.PolicyStatementProps;
8+
import software.amazon.awscdk.services.lambda.Code;
9+
import software.amazon.awscdk.services.lambda.Function;
10+
import software.amazon.awscdk.services.lambda.FunctionProps;
11+
import software.amazon.awscdk.services.lambda.Runtime;
12+
import software.amazon.awscdk.services.s3.assets.AssetOptions;
13+
import software.constructs.Construct;
14+
15+
import java.io.Serializable;
16+
import java.util.Arrays;
17+
import java.util.Collections;
18+
import java.util.HashMap;
19+
import java.util.List;
20+
import java.util.Map;
21+
22+
23+
import static java.util.Collections.singletonList;
24+
import static software.amazon.awscdk.BundlingOutput.NOT_ARCHIVED;
25+
26+
public class PowertoolsExamplesCloudformationCdkStack extends Stack {
27+
28+
public static final String SAMPLE_BUCKET_NAME = "sample-bucket-name-20230315-abc123";
29+
30+
public PowertoolsExamplesCloudformationCdkStack(final Construct scope, final String id) {
31+
this(scope, id, null);
32+
}
33+
34+
public PowertoolsExamplesCloudformationCdkStack(final Construct scope, final String id, final StackProps props) {
35+
super(scope, id, props);
36+
37+
38+
List<String> functionPackagingInstructions = Arrays.asList(
39+
"/bin/sh",
40+
"-c",
41+
"mvn clean install" +
42+
"&& mkdir /asset-output/lib" +
43+
"&& cp target/powertools-examples-cloudformation-*.jar /asset-output/lib"
44+
);
45+
BundlingOptions bundlingOptions = BundlingOptions.builder()
46+
.command(functionPackagingInstructions)
47+
.image(Runtime.JAVA_11.getBundlingImage())
48+
.volumes(singletonList(
49+
// Mount local .m2 repo to avoid download all the dependencies again inside the container
50+
DockerVolume.builder()
51+
.hostPath(System.getProperty("user.home") + "/.m2/")
52+
.containerPath("/root/.m2/")
53+
.build()
54+
))
55+
.user("root")
56+
.outputType(NOT_ARCHIVED)
57+
.build();
58+
59+
Function helloWorldFunction = new Function(this, "HelloWorldFunction", FunctionProps.builder()
60+
.runtime(Runtime.JAVA_11)
61+
.code(Code.fromAsset("../../", AssetOptions.builder().bundling(bundlingOptions)
62+
.build()))
63+
.handler("helloworld.App::handleRequest")
64+
.memorySize(512)
65+
.timeout(Duration.seconds(20))
66+
.environment(Collections
67+
.singletonMap("JAVA_TOOL_OPTIONS", "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"))
68+
.build());
69+
helloWorldFunction.addToRolePolicy(new PolicyStatement(PolicyStatementProps.builder()
70+
.effect(Effect.ALLOW)
71+
.actions(Arrays.asList("s3:GetLifecycleConfiguration",
72+
"s3:PutLifecycleConfiguration",
73+
"s3:CreateBucket",
74+
"s3:ListBucket",
75+
"s3:DeleteBucket"))
76+
.resources(singletonList("*")).build()));
77+
78+
String bucketName = (String) this.getNode().tryGetContext("BucketNameParam");
79+
80+
Map<String, Serializable> crProperties = new HashMap<>();
81+
crProperties.put("BucketName", bucketName);
82+
CustomResource.Builder
83+
.create(this, "HelloWorldCustomResource")
84+
.serviceToken(helloWorldFunction.getFunctionArn())
85+
.properties(crProperties)
86+
.build();
87+
88+
}
89+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"RequestType": "Create",
3+
"ResponseURL": "http://pre-signed-S3-url-for-response",
4+
"StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/MyStack/guid",
5+
"RequestId": "unique id for this create request",
6+
"ResourceType": "Custom::TestResource",
7+
"ResourceProperties": {
8+
"BucketName": "test-bucket-20230307-1",
9+
"RetentionDays" : 10,
10+
"StackName": "MyStack"
11+
}
12+
}

0 commit comments

Comments
 (0)