Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5d5c0ca

Browse filesBrowse files
committed
java 17 currently too big to unzip as a layer
1 parent fe472c7 commit 5d5c0ca
Copy full SHA for 5d5c0ca

File tree

Expand file treeCollapse file tree

11 files changed

+382
-0
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+382
-0
lines changed

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
/jdk-17/
25+
/.idea/
26+
/example/software/ExampleFunction/target/
27+
28+
*.iml

‎bootstrap

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
#export _JAVA_OPTIONS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
4+
5+
/opt/jdk-17/bin/java -cp aws-lambda-java-runtime-interface-client-1.1.0.jar com.amazonaws.services.lambda.runtime.api.client.AWSLambda "$_HANDLER"

‎example/infrastructure/.gitignore

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
outputs.json
14+

‎example/infrastructure/cdk.json

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"app": "mvn -e -q compile exec:java",
3+
"context": {
4+
"@aws-cdk/core:enableStackNameDuplicates": "true",
5+
"aws-cdk:enableDiffNoFail": "true",
6+
"@aws-cdk/core:stackRelativeExports": "true",
7+
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true,
8+
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true,
9+
"@aws-cdk/aws-kms:defaultKeyPolicies": true,
10+
"@aws-cdk/aws-s3:grantWriteWithoutAcl": true
11+
}
12+
}

‎example/infrastructure/loadtest.yml

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
config:
2+
phases:
3+
- duration: 300
4+
arrivalRate: 120
5+
scenarios:
6+
- flow:
7+
- get:
8+
url: "{{ url }}"

‎example/infrastructure/pom.xml

Copy file name to clipboard
+70Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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>example</groupId>
7+
<artifactId>infrastructure</artifactId>
8+
<version>0.1</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<cdk.version>1.87.1</cdk.version>
13+
<junit.version>5.7.0</junit.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>9</source>
24+
<target>9</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>example.InfrastructureApp</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>core</artifactId>
44+
<version>${cdk.version}</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>software.amazon.awscdk</groupId>
49+
<artifactId>lambda</artifactId>
50+
<version>${cdk.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>software.amazon.awscdk</groupId>
54+
<artifactId>apigatewayv2</artifactId>
55+
<version>${cdk.version}</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>software.amazon.awscdk</groupId>
59+
<artifactId>apigatewayv2-integrations</artifactId>
60+
<version>${cdk.version}</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>software.amazon.awscdk</groupId>
64+
<artifactId>dynamodb</artifactId>
65+
<version>${cdk.version}</version>
66+
</dependency>
67+
68+
69+
</dependencies>
70+
</project>
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package example;
2+
3+
import software.amazon.awscdk.core.App;
4+
5+
public class InfrastructureApp {
6+
public static void main(final String[] args) {
7+
App app = new App();
8+
9+
new InfrastructureStack(app, "InfrastructureStack");
10+
11+
app.synth();
12+
}
13+
}
+99Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package example;
2+
3+
import software.amazon.awscdk.core.CfnOutput;
4+
import software.amazon.awscdk.core.CfnOutputProps;
5+
import software.amazon.awscdk.core.Construct;
6+
import software.amazon.awscdk.core.Duration;
7+
import software.amazon.awscdk.core.Stack;
8+
import software.amazon.awscdk.core.StackProps;
9+
import software.amazon.awscdk.services.apigatewayv2.AddRoutesOptions;
10+
import software.amazon.awscdk.services.apigatewayv2.HttpApi;
11+
import software.amazon.awscdk.services.apigatewayv2.HttpApiProps;
12+
import software.amazon.awscdk.services.apigatewayv2.HttpMethod;
13+
import software.amazon.awscdk.services.apigatewayv2.PayloadFormatVersion;
14+
import software.amazon.awscdk.services.apigatewayv2.integrations.LambdaProxyIntegration;
15+
import software.amazon.awscdk.services.apigatewayv2.integrations.LambdaProxyIntegrationProps;
16+
import software.amazon.awscdk.services.dynamodb.Attribute;
17+
import software.amazon.awscdk.services.dynamodb.AttributeType;
18+
import software.amazon.awscdk.services.dynamodb.BillingMode;
19+
import software.amazon.awscdk.services.dynamodb.Table;
20+
import software.amazon.awscdk.services.dynamodb.TableProps;
21+
import software.amazon.awscdk.services.lambda.Code;
22+
import software.amazon.awscdk.services.lambda.Function;
23+
import software.amazon.awscdk.services.lambda.FunctionProps;
24+
import software.amazon.awscdk.services.lambda.LayerVersion;
25+
import software.amazon.awscdk.services.lambda.LayerVersionProps;
26+
import software.amazon.awscdk.services.lambda.Runtime;
27+
import software.amazon.awscdk.services.logs.RetentionDays;
28+
29+
import java.util.Arrays;
30+
import java.util.HashMap;
31+
import java.util.Map;
32+
33+
import static java.util.Collections.singletonList;
34+
35+
public class InfrastructureStack extends Stack {
36+
public InfrastructureStack(final Construct scope, final String id) {
37+
this(scope, id, null);
38+
}
39+
40+
public InfrastructureStack(final Construct scope, final String id, final StackProps props) {
41+
super(scope, id, props);
42+
43+
Table exampleTable = new Table(this, "ExampleTable", TableProps.builder()
44+
.partitionKey(Attribute.builder()
45+
.type(AttributeType.STRING)
46+
.name("id").build())
47+
.billingMode(BillingMode.PAY_PER_REQUEST)
48+
.build());
49+
50+
LayerVersion java17layer = new LayerVersion(this, "Java17Layer", LayerVersionProps.builder()
51+
.layerVersionName("Java17Layer")
52+
.description("Java 17")
53+
.compatibleRuntimes(Arrays.asList(Runtime.PROVIDED_AL2))
54+
.code(Code.fromAsset("../../java17layer.zip"))
55+
.build());
56+
57+
Function exampleWithLayer = new Function(this, "ExampleWithLayer", FunctionProps.builder()
58+
.functionName("example-with-layer")
59+
.description("example-with-layer")
60+
.handler("example.ExampleDynamoDbHandler::handleRequest")
61+
.runtime(Runtime.PROVIDED_AL2)
62+
.code(Code.fromAsset("../software/ExampleFunction/target/example.jar"))
63+
.memorySize(512)
64+
.environment(mapOf("TABLE_NAME", exampleTable.getTableName()))
65+
.timeout(Duration.seconds(20))
66+
.logRetention(RetentionDays.ONE_WEEK)
67+
.layers(singletonList(java17layer))
68+
.build());
69+
70+
exampleTable.grantWriteData(exampleWithLayer);
71+
72+
HttpApi httpApi = new HttpApi(this, "ExampleApi", HttpApiProps.builder()
73+
.apiName("ExampleApi")
74+
.build());
75+
76+
httpApi.addRoutes(AddRoutesOptions.builder()
77+
.path("/with")
78+
.methods(singletonList(HttpMethod.GET))
79+
.integration(new LambdaProxyIntegration(LambdaProxyIntegrationProps.builder()
80+
.handler(exampleWithLayer)
81+
.payloadFormatVersion(PayloadFormatVersion.VERSION_2_0)
82+
.build()))
83+
.build());
84+
85+
new CfnOutput(this, "api-endpoint", CfnOutputProps.builder()
86+
.value(httpApi.getApiEndpoint())
87+
.build());
88+
}
89+
90+
private Map<String, String> mapOf(String... keyValues) {
91+
Map<String, String> map = new HashMap<>(keyValues.length/2);
92+
for (int i = 0; i < keyValues.length; i++) {
93+
if(i % 2 == 0) {
94+
map.put(keyValues[i], keyValues[i + 1]);
95+
}
96+
}
97+
return map;
98+
}
99+
}
+87Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>example</groupId>
5+
<artifactId>example</artifactId>
6+
<version>1.0</version>
7+
<packaging>jar</packaging>
8+
<name>A sample Lambda function created for SAM CLI.</name>
9+
<properties>
10+
<aws.java.sdk.version>2.16.1</aws.java.sdk.version>
11+
</properties>
12+
13+
<dependencyManagement>
14+
<dependencies>
15+
<dependency>
16+
<groupId>software.amazon.awssdk</groupId>
17+
<artifactId>bom</artifactId>
18+
<version>${aws.java.sdk.version}</version>
19+
<type>pom</type>
20+
<scope>import</scope>
21+
</dependency>
22+
</dependencies>
23+
</dependencyManagement>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>com.amazonaws</groupId>
28+
<artifactId>aws-lambda-java-core</artifactId>
29+
<version>1.2.1</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.amazonaws</groupId>
33+
<artifactId>aws-lambda-java-events</artifactId>
34+
<version>3.6.0</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>software.amazon.awssdk</groupId>
39+
<artifactId>dynamodb</artifactId>
40+
<exclusions>
41+
<exclusion>
42+
<groupId>software.amazon.awssdk</groupId>
43+
<artifactId>netty-nio-client</artifactId>
44+
</exclusion>
45+
<exclusion>
46+
<groupId>software.amazon.awssdk</groupId>
47+
<artifactId>apache-client</artifactId>
48+
</exclusion>
49+
</exclusions>
50+
</dependency>
51+
<dependency>
52+
<groupId>software.amazon.awssdk</groupId>
53+
<artifactId>url-connection-client</artifactId>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-shade-plugin</artifactId>
62+
<version>3.2.4</version>
63+
<configuration>
64+
<finalName>example</finalName>
65+
</configuration>
66+
<executions>
67+
<execution>
68+
<phase>package</phase>
69+
<goals>
70+
<goal>shade</goal>
71+
</goals>
72+
</execution>
73+
</executions>
74+
</plugin>
75+
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-compiler-plugin</artifactId>
79+
<version>3.8.1</version>
80+
<configuration>
81+
<source>1.8</source>
82+
<target>1.8</target>
83+
</configuration>
84+
</plugin>
85+
</plugins>
86+
</build>
87+
</project>
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package example;
2+
3+
import com.amazonaws.services.lambda.runtime.Context;
4+
import com.amazonaws.services.lambda.runtime.RequestHandler;
5+
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
6+
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
7+
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
8+
import software.amazon.awssdk.core.SdkSystemSetting;
9+
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
10+
import software.amazon.awssdk.regions.Region;
11+
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
12+
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
13+
import software.amazon.awssdk.services.dynamodb.model.DynamoDbException;
14+
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest;
15+
16+
import java.util.HashMap;
17+
import java.util.Map;
18+
import java.util.UUID;
19+
import java.util.stream.Collectors;
20+
21+
public class ExampleDynamoDbHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
22+
23+
private static final String TABLE_NAME = System.getenv("TABLE_NAME");
24+
25+
private final DynamoDbClient dynamoDbClient = DynamoDbClient.builder()
26+
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
27+
.region(Region.of(System.getenv(SdkSystemSetting.AWS_REGION.environmentVariable())))
28+
.httpClientBuilder(UrlConnectionHttpClient.builder())
29+
.build();
30+
31+
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
32+
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
33+
34+
context.getLogger().log(input.toString());
35+
36+
try {
37+
Map<String, AttributeValue> itemAttributes = new HashMap<>();
38+
itemAttributes.put("id", AttributeValue.builder().s(context.getAwsRequestId()).build());
39+
itemAttributes.put("value",
40+
AttributeValue.builder().s(
41+
input.getHeaders().entrySet()
42+
.stream()
43+
.map(a -> a.getKey()+"="+a.getValue())
44+
.collect(Collectors.joining())
45+
).build()
46+
);
47+
48+
dynamoDbClient.putItem(PutItemRequest.builder()
49+
.tableName(TABLE_NAME)
50+
.item(itemAttributes)
51+
.build());
52+
return response.withBody("successful").withStatusCode(200);
53+
} catch (DynamoDbException e) {
54+
context.getLogger().log(e.getMessage());
55+
return response.withBody("error").withStatusCode(500);
56+
}
57+
}
58+
59+
}

‎make-layer.sh

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# -4 IPv4 only
4+
# -L follow redirect if the server responds with a redirect
5+
6+
curl -4 -L https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-x64_bin.tar.gz | tar -xvz
7+
curl -4 -L https://repo.maven.apache.org/maven2/com/amazonaws/aws-lambda-java-runtime-interface-client/1.1.0/aws-lambda-java-runtime-interface-client-1.1.0.jar -o aws-lambda-java-runtime-interface-client-1.1.0.jar
8+
9+
10+
chmod 755 bootstrap && zip -r java17layer.zip jdk-17 bootstrap aws-lambda-java-runtime-interface-client-1.1.0.jar

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.