Skip to content

Commit f3cf963

Browse files
committedSep 18, 2020
Initial commit
0 parents  commit f3cf963

File tree

17 files changed

+671
-0
lines changed

17 files changed

+671
-0
lines changed
 

‎.gitignore

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# IntelliJ
2+
.idea/
3+
*.iml
4+
5+
# Build artifacts
6+
target/
7+
8+
# Gradle
9+
.gradle
10+
build
11+
12+
# Compile Java classes
13+
*.class
14+
15+
# Log files
16+
logs
17+
*.log
18+
19+
# Runtime data
20+
pids
21+
*.pid
22+
*.seed
23+
*.pid.lock
24+
25+
# macOS
26+
.DS_Store
27+
.AppleDouble
28+
.LSOverride
29+
30+
# Icon
31+
Icon
32+
33+
# Thumbnails
34+
._*
35+
36+
# Files that might appear in the root of a volume
37+
.DocumentRevisions-V100
38+
.fseventsd
39+
.Spotlight-V100
40+
.TemporaryItems
41+
.Trashes
42+
.VolumeIcon.icns
43+
.com.apple.timemachine.donotpresent
44+
45+
# Directories potentially created on remote AFP share
46+
.AppleDB
47+
.AppleDesktop
48+
Network Trash Folder
49+
Temporary Items
50+
.apdisk
51+
52+
# Windows
53+
Thumbs.db
54+
ehthumbs.db
55+
ehthumbs_vista.db

‎README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Java CDK Starter
2+
3+
## How to Deploy
4+
5+
1. In `lambda` directory
6+
1. Run `../gradlew build`
7+
1. In `cdk` directory
8+
1. Run `../gradlew build`
9+
1. Run `cdk diff` then `cdk deploy`
10+
11+
## Todo
12+
13+
1. Find a way to share output sources from `lambda` module
14+
rather than using absolute path in `cdk` module' `CdkJavaStack`

‎build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*
4+
* This is a general purpose Gradle build.
5+
* Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds
6+
*/

‎cdk/.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
cdk.out/
2+
3+
# IntelliJ
4+
.idea/
5+
*.iml
6+
7+
# Build artifacts
8+
target/
9+
10+
# Gradle
11+
.gradle
12+
build
13+
14+
# Compile Java classes
15+
*.class
16+
17+
# Log files
18+
logs
19+
*.log
20+
21+
# Runtime data
22+
pids
23+
*.pid
24+
*.seed
25+
*.pid.lock
26+
27+
# macOS
28+
.DS_Store
29+
.AppleDouble
30+
.LSOverride
31+
32+
# Icon
33+
Icon
34+
35+
# Thumbnails
36+
._*
37+
38+
# Files that might appear in the root of a volume
39+
.DocumentRevisions-V100
40+
.fseventsd
41+
.Spotlight-V100
42+
.TemporaryItems
43+
.Trashes
44+
.VolumeIcon.icns
45+
.com.apple.timemachine.donotpresent
46+
47+
# Directories potentially created on remote AFP share
48+
.AppleDB
49+
.AppleDesktop
50+
Network Trash Folder
51+
Temporary Items
52+
.apdisk
53+
54+
# Windows
55+
Thumbs.db
56+
ehthumbs.db
57+
ehthumbs_vista.db

‎cdk/build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
plugins {
2+
id 'java'
3+
id 'application'
4+
}
5+
6+
repositories {
7+
mavenLocal()
8+
maven {
9+
url = 'https://repo.maven.apache.org/maven2'
10+
}
11+
}
12+
13+
application {
14+
mainClassName = 'com.davidagood.cdkjava.CdkJavaApp'
15+
}
16+
17+
dependencies {
18+
implementation project(':lambda')
19+
implementation 'software.amazon.awscdk:core:1.62.0'
20+
implementation 'software.amazon.awscdk:dynamodb:1.62.0'
21+
implementation 'software.amazon.awscdk:lambda:1.62.0'
22+
testImplementation 'junit:junit:4.12'
23+
}
24+
25+
group = 'com.davidagood'
26+
version = '0.1'
27+
sourceCompatibility = '1.8'
28+
29+
tasks.withType(JavaCompile) {
30+
options.encoding = 'UTF-8'
31+
}

‎cdk/cdk.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"app": "../gradlew run",
3+
"context": {
4+
"@aws-cdk/core:enableStackNameDuplicates": "true",
5+
"aws-cdk:enableDiffNoFail": "true",
6+
"@aws-cdk/core:stackRelativeExports": "true"
7+
}
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.davidagood.cdkjava;
2+
3+
import software.amazon.awscdk.core.App;
4+
5+
public final class CdkJavaApp {
6+
public static void main(final String[] args) {
7+
App app = new App();
8+
new CdkJavaStack(app, "CdkJavaStack");
9+
app.synth();
10+
}
11+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.davidagood.cdkjava;
2+
3+
import software.amazon.awscdk.core.Construct;
4+
import software.amazon.awscdk.core.Stack;
5+
import software.amazon.awscdk.core.StackProps;
6+
import software.amazon.awscdk.services.dynamodb.Attribute;
7+
import software.amazon.awscdk.services.dynamodb.AttributeType;
8+
import software.amazon.awscdk.services.dynamodb.Table;
9+
import software.amazon.awscdk.services.lambda.Code;
10+
import software.amazon.awscdk.services.lambda.Function;
11+
import software.amazon.awscdk.services.lambda.Runtime;
12+
13+
public class CdkJavaStack extends Stack {
14+
public CdkJavaStack(final Construct parent, final String id) {
15+
this(parent, id, null);
16+
}
17+
18+
public CdkJavaStack(final Construct parent, final String id, final StackProps props) {
19+
super(parent, id, props);
20+
21+
Table table = Table.Builder.create(this, "ExampleTable")
22+
.partitionKey(Attribute.builder().name("PK").type(AttributeType.STRING).build())
23+
.sortKey(Attribute.builder().name("SK").type(AttributeType.STRING).build())
24+
.build();
25+
26+
Code codeFromLocalPath = Code.fromAsset("/Users/davidgood/dev/cdk-java-gradle-multi-module/lambda/build/libs/lambda-uber.jar");
27+
28+
Function function = Function.Builder.create(this, "test-func-cdk")
29+
.code(codeFromLocalPath)
30+
.handler("com.davidagood.cdkjava.ExampleHandler::handleRequest")
31+
.runtime(Runtime.JAVA_8)
32+
.build();
33+
}
34+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.davidagood.cdkjava;
2+
3+
import org.junit.Ignore;
4+
import software.amazon.awscdk.core.App;
5+
import com.fasterxml.jackson.databind.JsonNode;
6+
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import com.fasterxml.jackson.databind.SerializationFeature;
8+
import org.junit.Test;
9+
10+
import static org.junit.Assert.assertEquals;
11+
12+
public class CdkTest {
13+
private final static ObjectMapper JSON =
14+
new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true);
15+
16+
@Test
17+
@Ignore
18+
public void testStack() {
19+
App app = new App();
20+
CdkJavaStack stack = new CdkJavaStack(app, "test");
21+
22+
// synthesize the stack to a CloudFormation template and compare against
23+
// a checked-in JSON file.
24+
JsonNode actual = JSON.valueToTree(app.synth().getStackArtifact(stack.getArtifactId()).getTemplate());
25+
assertEquals(new ObjectMapper().createObjectNode(), actual);
26+
}
27+
}

‎gradle/wrapper/gradle-wrapper.jar

57.3 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Thu Sep 17 09:26:57 EDT 2020
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
3+
distributionBase=GRADLE_USER_HOME
4+
distributionPath=wrapper/dists
5+
zipStorePath=wrapper/dists
6+
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)