Skip to content

Commit c384dec

Browse files
Merge pull request #239 from patmeiler/pameiler-java-cdk
[New Language Support] Added Java CDK
2 parents 6ede8f0 + b9e147c commit c384dec

File tree

8 files changed

+279
-0
lines changed

8 files changed

+279
-0
lines changed

cdk/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Currently we support:
88
- [C#](csharp/README.md)
99
- [Python](python/README.md)
1010
- [go](go/README.md)
11+
- [Java](java/README.md)
1112

1213
You can use these projects as a standalone or reuse it within your own CDK projects.
1314

cdk/java/.gitignore

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+

cdk/java/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# How to deploy the AWS Lambda Power Tuning using the CDK for Java
2+
3+
This CDK project deploys *AWS Lambda Power Tuning* using Java.
4+
5+
You can use the project as a standalone or reuse it within your own CDK projects.
6+
7+
8+
## CDK Prerequisites
9+
10+
See [here](../README.md).
11+
12+
13+
## Language specific prerequisites
14+
- [Java Development Kit (JDK) 8 (a.k.a. 1.8) or later](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_prerequisites)
15+
- [Apache Maven 3.5 or later](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_prerequisites)
16+
- [Requirements for CDK with Java](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-java.html)
17+
18+
## Building, testing, and deploying the app
19+
* `mvn package` compile and run tests
20+
* `cdk synth` emits the synthesized CloudFormation template
21+
* `cdk deploy` deploy this app
22+
23+
The `cdk.json` file tells the CDK Toolkit how to execute your app.
24+
25+
It is a [Maven](https://maven.apache.org/) based project, so you can open this project with any Maven compatible Java IDE to build and run tests.

cdk/java/cdk.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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-iam:importedRoleStackSafeDefaultPolicyName": true,
36+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
37+
"@aws-cdk/aws-route53-patters:useCertificate": true,
38+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
39+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
40+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
41+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
42+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
43+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
44+
"@aws-cdk/aws-redshift:columnId": true,
45+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
46+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
47+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
48+
"@aws-cdk/aws-kms:aliasNameRef": true,
49+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
50+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
51+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
52+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
53+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
54+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
55+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
56+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
57+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
58+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true
59+
}
60+
}

cdk/java/pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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>java</artifactId>
8+
<version>0.1</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<cdk.version>2.114.1</cdk.version>
13+
<constructs.version>[10.0.0,11.0.0)</constructs.version>
14+
<junit.version>5.7.1</junit.version>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-compiler-plugin</artifactId>
22+
<version>3.11.0</version>
23+
<configuration>
24+
<release>17</release>
25+
</configuration>
26+
</plugin>
27+
28+
<plugin>
29+
<groupId>org.codehaus.mojo</groupId>
30+
<artifactId>exec-maven-plugin</artifactId>
31+
<version>3.1.0</version>
32+
<configuration>
33+
<mainClass>com.myorg.TheLambdaPowerTunerApp</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+
53+
<dependency>
54+
<groupId>org.junit.jupiter</groupId>
55+
<artifactId>junit-jupiter</artifactId>
56+
<version>${junit.version}</version>
57+
<scope>test</scope>
58+
</dependency>
59+
</dependencies>
60+
</project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.myorg;
2+
3+
import software.amazon.awscdk.App;
4+
import software.amazon.awscdk.StackProps;
5+
6+
public class TheLambdaPowerTunerApp {
7+
public static void main(final String[] args) {
8+
App app = new App();
9+
10+
new TheLambdaPowerTunerStack(app, "JavaStack", StackProps.builder()
11+
// If you don't specify 'env', this stack will be environment-agnostic.
12+
// Account/Region-dependent features and context lookups will not work,
13+
// but a single synthesized template can be deployed anywhere.
14+
15+
// Uncomment the next block to specialize this stack for the AWS Account
16+
// and Region that are implied by the current CLI configuration.
17+
/*
18+
.env(Environment.builder()
19+
.account(System.getenv("CDK_DEFAULT_ACCOUNT"))
20+
.region(System.getenv("CDK_DEFAULT_REGION"))
21+
.build())
22+
*/
23+
24+
// Uncomment the next block if you know exactly what Account and Region you
25+
// want to deploy the stack to.
26+
/*
27+
.env(Environment.builder()
28+
.account("123456789012")
29+
.region("us-east-1")
30+
.build())
31+
*/
32+
33+
// For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
34+
.build());
35+
36+
app.synth();
37+
}
38+
}
39+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.myorg;
2+
3+
import software.constructs.Construct;
4+
5+
import software.amazon.awscdk.Stack;
6+
import software.amazon.awscdk.StackProps;
7+
import software.amazon.awscdk.services.sam.CfnApplication;
8+
import software.amazon.awscdk.services.sam.CfnApplication.ApplicationLocationProperty;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
public class TheLambdaPowerTunerStack extends Stack {
13+
14+
//Set constants
15+
private static final String SAR_APPLICATION_ID = "arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning";
16+
private static final String SAR_SEMANTIC_VERSION = "4.3.4";
17+
18+
public TheLambdaPowerTunerStack(final Construct scope, final String id) {
19+
this(scope, id, null);
20+
}
21+
22+
public TheLambdaPowerTunerStack(final Construct scope, final String id, final StackProps props) {
23+
super(scope, id, props);
24+
25+
//create an empty Map
26+
Map<String,String> parameters = new HashMap<>();
27+
28+
// parameters.put("lambdaResource", "*")
29+
// parameters.put("PowerValues", "128,256,512,1024,1536,3008")
30+
// parameters.put("visualizationURL", "https://lambda-power-tuning.shw/")
31+
// parameters.put("totalExecutionTimeout", "300")
32+
// parameters.put("payloadS3Key", "*")
33+
// parameters.put("logGroupRetentionInDays", "7")
34+
// parameters.put("stateMachineNamePrefix", "powerTuningStateMachine")
35+
// parameters.put("permissionsBoundary", "<ARN of permission boundary>")
36+
// parameters.put("payloadS3Bucket", "<S3 bucket name used for large payloads>")
37+
// parameters.put("layerSdkName", "<name of the SDK layer>")
38+
// parameters.put("securityGroupIds", "<List of Security Groups to use in every Lambda function's VPC Configuration>")
39+
// parameters.put("subnetIds", "<List of Subnets to use in every Lambda function's VPC Configuration>")
40+
// parameters.put("lambdaResource", "*")
41+
42+
43+
CfnApplication cfnApplication = CfnApplication.Builder.create(this, "SAR")
44+
.location(
45+
ApplicationLocationProperty.builder()
46+
.applicationId(SAR_APPLICATION_ID)
47+
.semanticVersion(SAR_SEMANTIC_VERSION)
48+
.build()
49+
)
50+
.parameters(parameters)
51+
.build();
52+
}
53+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.myorg;
2+
3+
import software.amazon.awscdk.App;
4+
import software.amazon.awscdk.assertions.Template;
5+
import java.io.IOException;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
public class JavaTest {
13+
14+
@Test
15+
public void testStack() throws IOException {
16+
App app = new App();
17+
TheLambdaPowerTunerStack stack = new TheLambdaPowerTunerStack(app, "test");
18+
19+
Template template = Template.fromStack(stack);
20+
Map<String, String> child = new HashMap<>();
21+
Map<String, Object> root = new HashMap<>();
22+
23+
root.put("Location", child);
24+
child.put("ApplicationId", "arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning");
25+
26+
template.hasResourceProperties("AWS::Serverless::Application", root);
27+
}
28+
}

0 commit comments

Comments
 (0)