Skip to content

Commit

Permalink
refactor: curated lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Marie committed Sep 4, 2020
1 parent c6d746e commit d9861bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
import * as sns from '@aws-cdk/aws-sns';
import * as subs from '@aws-cdk/aws-sns-subscriptions';
import * as sqs from '@aws-cdk/aws-sqs';
import * as cdk from '@aws-cdk/core';

export interface %name.PascalCased%Props {
/**
* The visibility timeout to be configured on the SQS Queue, in seconds.
*
* @default Duration.seconds(300)
*/
visibilityTimeout?: cdk.Duration;

}

export class %name.PascalCased% extends cdk.Construct {
/** @returns the ARN of the SQS queue */
public readonly queueArn: string;

constructor(scope: cdk.Construct, id: string, props: %name.PascalCased%Props = {}) {
super(scope, id);

const queue = new sqs.Queue(this, '%name.PascalCased%Queue', {
visibilityTimeout: props.visibilityTimeout || cdk.Duration.seconds(300)
});

const topic = new sns.Topic(this, '%name.PascalCased%Topic');

topic.addSubscription(new subs.SqsSubscription(queue));

this.queueArn = queue.queueArn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"@aws-cdk/core": "%cdk-version%"
},
"dependencies": {
"@aws-cdk/aws-sns": "%cdk-version%",
"@aws-cdk/aws-sns-subscriptions": "%cdk-version%",
"@aws-cdk/aws-sqs": "%cdk-version%",
"@aws-cdk/core": "%cdk-version%"
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { expect as expectCDK, haveResource } from '@aws-cdk/assert';
import { expect as expectCDK, countResources } from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import * as %name.PascalCased% from '../lib/index';

test('SQS Queue Created', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, "TestStack");
// WHEN
new %name.PascalCased%.%name.PascalCased%(stack, 'MyTestConstruct');
// THEN
expectCDK(stack).to(haveResource("AWS::SQS::Queue"));
});

/*
* Example test
*/
test('SNS Topic Created', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, "TestStack");
// WHEN
new %name.PascalCased%.%name.PascalCased%(stack, 'MyTestConstruct');
// THEN
expectCDK(stack).to(haveResource("AWS::SNS::Topic"));
expectCDK(stack).to(countResources("AWS::SNS::Topic",0));
});

0 comments on commit d9861bf

Please sign in to comment.