Skip to content

Commit

Permalink
fix: CDK General Availability (1.0.0) updates (#76)
Browse files Browse the repository at this point in the history
Also build all examples in the PR build.
  • Loading branch information
skinny85 authored and rix0rrr committed Jul 12, 2019
1 parent 0833d70 commit d1e63af
Show file tree
Hide file tree
Showing 54 changed files with 158 additions and 133 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: node_js
language: generic
dist: bionic
node_js:
- "8"
python:
- "3.6"

install: echo Nothing to install
script: scripts/build-npm.sh

install: sudo apt-get install python3.6-venv
script: scripts/build.sh
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Create a directory with a name that is descriptive of the resource type or workf
```
{
"name": [name of your application],
"version": "0.23.0",
"version": "1.0.0",
"description": [description of your application],
"private": true,
"scripts": {
Expand All @@ -101,7 +101,7 @@ Create a directory with a name that is descriptive of the resource type or workf
},
"dependencies": {
...
"@aws-cdk/core": "^0.36.0"
"@aws-cdk/core": "^1.0.0"
}
}
```
Expand Down
2 changes: 2 additions & 0 deletions java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ target
.classpath
.project
.settings
node_modules
package-lock.json
29 changes: 14 additions & 15 deletions java/hello-world/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,56 +52,55 @@
</build>

<dependencies>
<dependency>
<groupId>software.amazon.jsii</groupId>
<artifactId>jsii-runtime</artifactId>
<version>0.7.14</version>
</dependency>

<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>cdk</artifactId>
<version>0.23.0</version>
<artifactId>core</artifactId>
<version>1.0.0.DEVPREVIEW</version>
</dependency>
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>autoscaling</artifactId>
<version>0.23.0</version>
<version>1.0.0.DEVPREVIEW</version>
</dependency>

<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>ec2</artifactId>
<version>0.23.0</version>
<version>1.0.0.DEVPREVIEW</version>
</dependency>
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>s3</artifactId>
<version>0.23.0</version>
<version>1.0.0.DEVPREVIEW</version>
</dependency>
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>sns</artifactId>
<version>0.23.0</version>
<version>1.0.0.DEVPREVIEW</version>
</dependency>
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>sqs</artifactId>
<version>0.23.0</version>
<version>1.0.0.DEVPREVIEW</version>
</dependency>
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>sns-subscriptions</artifactId>
<version>1.0.0.DEVPREVIEW</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>[2.9.8,)</version>
<version>2.9.8</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>[2.9.8,)</version>
<version>2.9.8</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package software.amazon.awscdk.examples;

import software.amazon.awscdk.App;
import software.amazon.awscdk.core.App;

public class HelloJavaApp {
public static void main(final String[] args) {
App app = new App();

new HelloJavaStack(app, "hello-cdk");

app.run();
app.synth();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package software.amazon.awscdk.examples;

import software.amazon.awscdk.App;
import software.amazon.awscdk.Stack;
import software.amazon.awscdk.Construct;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.services.autoscaling.AutoScalingGroup;
import software.amazon.awscdk.services.autoscaling.AutoScalingGroupProps;
import software.amazon.awscdk.services.ec2.AmazonLinuxImage;
import software.amazon.awscdk.services.ec2.InstanceType;
import software.amazon.awscdk.services.ec2.VpcNetwork;
import software.amazon.awscdk.services.ec2.Vpc;
import software.amazon.awscdk.services.sns.Topic;

import java.util.Collections;
Expand All @@ -17,10 +16,10 @@
* Hello, CDK for Java!
*/
class HelloJavaStack extends Stack {
public HelloJavaStack(final App parent, final String name) {
public HelloJavaStack(final Construct parent, final String name) {
super(parent, name);

VpcNetwork vpc = new VpcNetwork(this, "VPC");
Vpc vpc = new Vpc(this, "VPC");

MyAutoScalingGroupProps autoScalingGroupProps = new MyAutoScalingGroupProps();
autoScalingGroupProps.vpc = vpc;
Expand All @@ -37,7 +36,7 @@ public HelloJavaStack(final App parent, final String name) {
}

static class MyAutoScalingGroupProps {
public VpcNetwork vpc;
public Vpc vpc;
}

static class MyAutoScalingGroup extends Construct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package software.amazon.awscdk.examples;

import software.amazon.awscdk.Construct;
import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.services.sns.Topic;
import software.amazon.awscdk.services.sns.subscriptions.SqsSubscription;
import software.amazon.awscdk.services.sqs.Queue;
import software.amazon.awscdk.services.sqs.QueueProps;

Expand Down Expand Up @@ -32,7 +33,7 @@ public SinkQueue(final Construct parent, final String name, SinkQueueProps props

// defaults
QueueProps queueProps = props.getQueueProps();
this.expectedTopicCount = props.getRequiredTopicCount() != null ? props.getRequiredTopicCount().intValue() : 10;
this.expectedTopicCount = props.getRequiredTopicCount() != null ? props.getRequiredTopicCount().intValue() : 0;

// WORKAROUND: https://github.com/awslabs/aws-cdk/issues/157
if (queueProps == null) {
Expand All @@ -58,10 +59,10 @@ public SinkQueue(final Construct parent, final String name) {
*/
public void subscribe(final Topic... topics) {
for (Topic topic: topics) {
if (actualTopicCount == expectedTopicCount) {
if (expectedTopicCount != 0 && actualTopicCount >= expectedTopicCount) {
throw new RuntimeException("Cannot add more topics to the sink. Maximum topics is configured to " + this.expectedTopicCount);
}
topic.subscribeQueue(this.queue);
topic.addSubscription(new SqsSubscription(this.queue));
actualTopicCount++;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package software.amazon.awscdk.examples;

import software.amazon.awscdk.App;
import software.amazon.awscdk.Stack;
import software.amazon.awscdk.core.App;
import software.amazon.awscdk.core.ConstructNode;
import software.amazon.awscdk.core.Duration;
import software.amazon.awscdk.core.IConstruct;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.cxapi.CloudFormationStackArtifact;
import software.amazon.awscdk.services.sns.Topic;
import software.amazon.awscdk.services.sqs.QueueProps;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -31,7 +35,7 @@ public class SinkQueueTest {
Stack stack = new Stack();
new SinkQueue(stack, "MySinkQueue", SinkQueueProps.builder()
.withQueueProps(QueueProps.builder()
.withVisibilityTimeoutSec(500)
.withVisibilityTimeout(Duration.seconds(500))
.build())
.build());
assertTemplate(stack, "{\n" +
Expand Down Expand Up @@ -92,7 +96,7 @@ public class SinkQueueTest {
sink.subscribe(new Topic(stack, "Topic" + i));
}

app.synthesizeStack(stack.getName());
getTemplate(stack);
}

private static void assertTemplate(final Stack stack, final URL expectedResource) throws IOException {
Expand All @@ -104,7 +108,7 @@ private static void assertTemplate(final Stack stack, final String expectedTempl
}

private static void assertTemplate(final Stack stack, final JsonNode expected) throws IOException {
JsonNode actual = JSON.valueToTree(stack.toCloudFormation());
JsonNode actual = JSON.valueToTree(getTemplate(stack));

// print to stderr if non-equal, so it will be easy to grab
if (expected == null || !expected.equals(actual)) {
Expand All @@ -114,4 +118,10 @@ private static void assertTemplate(final Stack stack, final JsonNode expected) t

assertEquals(expected, actual);
}

private static Object getTemplate(Stack stack) {
IConstruct root = stack.getNode().getRoot();
CloudFormationStackArtifact stackArtifact = ConstructNode.synth(root.getNode()).getStack(stack.getStackName());
return stackArtifact.getTemplate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"MySinkQueueEFCD79C2" : {
"Type" : "AWS::SQS::Queue"
},
"Topic1ResourceSubscriptionD55B1556" : {
"MySinkQueueTopic1CE70DEAE" : {
"Type" : "AWS::SNS::Subscription",
"Properties" : {
"Endpoint" : {
Expand Down Expand Up @@ -78,7 +78,7 @@
} ]
}
},
"Topic3ResourceSubscriptionA1D64BEE" : {
"MySinkQueueTopic30DEF4035" : {
"Type" : "AWS::SNS::Subscription",
"Properties" : {
"Endpoint" : {
Expand All @@ -93,7 +93,7 @@
"Topic269377B75" : {
"Type" : "AWS::SNS::Topic"
},
"Topic2ResourceSubscription88B54B51" : {
"MySinkQueueTopic227CE18C6" : {
"Type" : "AWS::SNS::Subscription",
"Properties" : {
"Endpoint" : {
Expand All @@ -109,4 +109,4 @@
"Type" : "AWS::SNS::Topic"
}
}
}
}
18 changes: 9 additions & 9 deletions java/lambda-cron/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,35 @@

<dependencies>
<dependency>
<groupId>software.amazon.jsii</groupId>
<artifactId>jsii-runtime</artifactId>
<version>0.7.14</version>
<groupId>software.amazon.awscdk</groupId>
<artifactId>core</artifactId>
<version>1.0.0.DEVPREVIEW</version>
</dependency>

<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>cdk</artifactId>
<version>0.23.0</version>
<artifactId>lambda</artifactId>
<version>1.0.0.DEVPREVIEW</version>
</dependency>

<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>lambda</artifactId>
<version>0.23.0</version>
<artifactId>events-targets</artifactId>
<version>1.0.0.DEVPREVIEW</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>[2.9.8,)</version>
<version>2.9.8</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>[2.9.8,)</version>
<version>2.9.8</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package software.amazon.awscdk.examples;

import software.amazon.awscdk.App;
import software.amazon.awscdk.core.App;

public class LambdaCronApp {
public static void main(final String[] args) {
App app = new App();

new LambdaCronStack(app, "cdk-lambda-cron-example");

app.run();
app.synth();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package software.amazon.awscdk.examples;

import software.amazon.awscdk.App;
import software.amazon.awscdk.Stack;
import software.amazon.awscdk.services.events.EventRule;
import software.amazon.awscdk.services.events.EventRuleProps;
import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.core.Duration;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.services.events.Rule;
import software.amazon.awscdk.services.events.RuleProps;
import software.amazon.awscdk.services.events.Schedule;
import software.amazon.awscdk.services.events.targets.LambdaFunction;
import software.amazon.awscdk.services.lambda.Code;
import software.amazon.awscdk.services.lambda.Runtime;
import software.amazon.awscdk.services.lambda.SingletonFunction;
Expand All @@ -15,7 +18,7 @@
* Lambda Cron CDK example for Java!
*/
class LambdaCronStack extends Stack {
public LambdaCronStack(final App parent, final String name) {
public LambdaCronStack(final Construct parent, final String name) {
super(parent, name);

SingletonFunction lambdaFunction = new SingletonFunction(this, "cdk-lambda-cron",
Expand All @@ -26,19 +29,19 @@ public LambdaCronStack(final App parent, final String name) {
"def main(event, context):\n" +
" print(\"I'm running!\")\n"))
.withHandler("index.main")
.withTimeout(300)
.withRuntime(Runtime.PYTHON27)
.withTimeout(Duration.seconds(300))
.withRuntime(Runtime.PYTHON_2_7)
.withUuid(UUID.randomUUID().toString())
.build()
);

EventRule rule = new EventRule(this, "cdk-lambda-cron-rule",
EventRuleProps.builder()
Rule rule = new Rule(this, "cdk-lambda-cron-rule",
RuleProps.builder()
.withDescription("Run every day at 6PM UTC")
.withScheduleExpression("cron(0 18 ? * MON-FRI *)")
.withSchedule(Schedule.expression("cron(0 18 ? * MON-FRI *)"))
.build()
);

rule.addTarget(lambdaFunction);
rule.addTarget(new LambdaFunction(lambdaFunction));
}
}
Loading

0 comments on commit d1e63af

Please sign in to comment.