-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from patmeiler/pameiler-java-cdk
[New Language Support] Added Java CDK
- Loading branch information
Showing
8 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.classpath.txt | ||
target | ||
.classpath | ||
.project | ||
.idea | ||
.settings | ||
.vscode | ||
*.iml | ||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# How to deploy the AWS Lambda Power Tuning using the CDK for Java | ||
|
||
This CDK project deploys *AWS Lambda Power Tuning* using Java. | ||
|
||
You can use the project as a standalone or reuse it within your own CDK projects. | ||
|
||
|
||
## CDK Prerequisites | ||
|
||
See [here](../README.md). | ||
|
||
|
||
## Language specific prerequisites | ||
- [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) | ||
- [Apache Maven 3.5 or later](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_prerequisites) | ||
- [Requirements for CDK with Java](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-java.html) | ||
|
||
## Building, testing, and deploying the app | ||
* `mvn package` compile and run tests | ||
* `cdk synth` emits the synthesized CloudFormation template | ||
* `cdk deploy` deploy this app | ||
|
||
The `cdk.json` file tells the CDK Toolkit how to execute your app. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"app": "mvn -e -q compile exec:java", | ||
"watch": { | ||
"include": [ | ||
"**" | ||
], | ||
"exclude": [ | ||
"README.md", | ||
"cdk*.json", | ||
"target", | ||
"pom.xml", | ||
"src/test" | ||
] | ||
}, | ||
"context": { | ||
"@aws-cdk/aws-lambda:recognizeLayerVersion": true, | ||
"@aws-cdk/core:checkSecretUsage": true, | ||
"@aws-cdk/core:target-partitions": [ | ||
"aws", | ||
"aws-cn" | ||
], | ||
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, | ||
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, | ||
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, | ||
"@aws-cdk/aws-iam:minimizePolicies": true, | ||
"@aws-cdk/core:validateSnapshotRemovalPolicy": true, | ||
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, | ||
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, | ||
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, | ||
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true, | ||
"@aws-cdk/core:enablePartitionLiterals": true, | ||
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true, | ||
"@aws-cdk/aws-iam:standardizedServicePrincipals": true, | ||
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true, | ||
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true, | ||
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true, | ||
"@aws-cdk/aws-route53-patters:useCertificate": true, | ||
"@aws-cdk/customresources:installLatestAwsSdkDefault": false, | ||
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true, | ||
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true, | ||
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true, | ||
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true, | ||
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true, | ||
"@aws-cdk/aws-redshift:columnId": true, | ||
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true, | ||
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true, | ||
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true, | ||
"@aws-cdk/aws-kms:aliasNameRef": true, | ||
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true, | ||
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true, | ||
"@aws-cdk/aws-efs:denyAnonymousAccess": true, | ||
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true, | ||
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true, | ||
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true, | ||
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true, | ||
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true, | ||
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true, | ||
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.myorg</groupId> | ||
<artifactId>java</artifactId> | ||
<version>0.1</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<cdk.version>2.114.1</cdk.version> | ||
<constructs.version>[10.0.0,11.0.0)</constructs.version> | ||
<junit.version>5.7.1</junit.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.11.0</version> | ||
<configuration> | ||
<release>17</release> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<configuration> | ||
<mainClass>com.myorg.TheLambdaPowerTunerApp</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<!-- AWS Cloud Development Kit --> | ||
<dependency> | ||
<groupId>software.amazon.awscdk</groupId> | ||
<artifactId>aws-cdk-lib</artifactId> | ||
<version>${cdk.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>software.constructs</groupId> | ||
<artifactId>constructs</artifactId> | ||
<version>${constructs.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
39 changes: 39 additions & 0 deletions
39
cdk/java/src/main/java/com/myorg/TheLambdaPowerTunerApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.myorg; | ||
|
||
import software.amazon.awscdk.App; | ||
import software.amazon.awscdk.StackProps; | ||
|
||
public class TheLambdaPowerTunerApp { | ||
public static void main(final String[] args) { | ||
App app = new App(); | ||
|
||
new TheLambdaPowerTunerStack(app, "JavaStack", StackProps.builder() | ||
// If you don't specify 'env', this stack will be environment-agnostic. | ||
// Account/Region-dependent features and context lookups will not work, | ||
// but a single synthesized template can be deployed anywhere. | ||
|
||
// Uncomment the next block to specialize this stack for the AWS Account | ||
// and Region that are implied by the current CLI configuration. | ||
/* | ||
.env(Environment.builder() | ||
.account(System.getenv("CDK_DEFAULT_ACCOUNT")) | ||
.region(System.getenv("CDK_DEFAULT_REGION")) | ||
.build()) | ||
*/ | ||
|
||
// Uncomment the next block if you know exactly what Account and Region you | ||
// want to deploy the stack to. | ||
/* | ||
.env(Environment.builder() | ||
.account("123456789012") | ||
.region("us-east-1") | ||
.build()) | ||
*/ | ||
|
||
// For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html | ||
.build()); | ||
|
||
app.synth(); | ||
} | ||
} | ||
|
53 changes: 53 additions & 0 deletions
53
cdk/java/src/main/java/com/myorg/TheLambdaPowerTunerStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.myorg; | ||
|
||
import software.constructs.Construct; | ||
|
||
import software.amazon.awscdk.Stack; | ||
import software.amazon.awscdk.StackProps; | ||
import software.amazon.awscdk.services.sam.CfnApplication; | ||
import software.amazon.awscdk.services.sam.CfnApplication.ApplicationLocationProperty; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class TheLambdaPowerTunerStack extends Stack { | ||
|
||
//Set constants | ||
private static final String SAR_APPLICATION_ID = "arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning"; | ||
private static final String SAR_SEMANTIC_VERSION = "4.3.4"; | ||
|
||
public TheLambdaPowerTunerStack(final Construct scope, final String id) { | ||
this(scope, id, null); | ||
} | ||
|
||
public TheLambdaPowerTunerStack(final Construct scope, final String id, final StackProps props) { | ||
super(scope, id, props); | ||
|
||
//create an empty Map | ||
Map<String,String> parameters = new HashMap<>(); | ||
|
||
// parameters.put("lambdaResource", "*") | ||
// parameters.put("PowerValues", "128,256,512,1024,1536,3008") | ||
// parameters.put("visualizationURL", "https://lambda-power-tuning.shw/") | ||
// parameters.put("totalExecutionTimeout", "300") | ||
// parameters.put("payloadS3Key", "*") | ||
// parameters.put("logGroupRetentionInDays", "7") | ||
// parameters.put("stateMachineNamePrefix", "powerTuningStateMachine") | ||
// parameters.put("permissionsBoundary", "<ARN of permission boundary>") | ||
// parameters.put("payloadS3Bucket", "<S3 bucket name used for large payloads>") | ||
// parameters.put("layerSdkName", "<name of the SDK layer>") | ||
// parameters.put("securityGroupIds", "<List of Security Groups to use in every Lambda function's VPC Configuration>") | ||
// parameters.put("subnetIds", "<List of Subnets to use in every Lambda function's VPC Configuration>") | ||
// parameters.put("lambdaResource", "*") | ||
|
||
|
||
CfnApplication cfnApplication = CfnApplication.Builder.create(this, "SAR") | ||
.location( | ||
ApplicationLocationProperty.builder() | ||
.applicationId(SAR_APPLICATION_ID) | ||
.semanticVersion(SAR_SEMANTIC_VERSION) | ||
.build() | ||
) | ||
.parameters(parameters) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.myorg; | ||
|
||
import software.amazon.awscdk.App; | ||
import software.amazon.awscdk.assertions.Template; | ||
import java.io.IOException; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class JavaTest { | ||
|
||
@Test | ||
public void testStack() throws IOException { | ||
App app = new App(); | ||
TheLambdaPowerTunerStack stack = new TheLambdaPowerTunerStack(app, "test"); | ||
|
||
Template template = Template.fromStack(stack); | ||
Map<String, String> child = new HashMap<>(); | ||
Map<String, Object> root = new HashMap<>(); | ||
|
||
root.put("Location", child); | ||
child.put("ApplicationId", "arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning"); | ||
|
||
template.hasResourceProperties("AWS::Serverless::Application", root); | ||
} | ||
} |