Skip to content

Commit

Permalink
PR feedback updates:
Browse files Browse the repository at this point in the history
* Removed references to lambda from .gitignore and .eslintignore
* Use service namespaces instead of named imports
* Updated architecture diagram
  • Loading branch information
Quinones committed Aug 4, 2021
1 parent e86c532 commit 3d0fde1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
lib/*.js
test/*.js
*.d.ts
coverage
test/lambda/index.js
coverage
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
lib/*.js
test/*.js
!test/lambda/*
*.js.map
*.d.ts
node_modules
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 27 additions & 29 deletions source/patterns/@aws-solutions-constructs/aws-iot-sqs/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
* and limitations under the License.
*/

import { Queue, QueueProps, DeadLetterQueue } from '@aws-cdk/aws-sqs';
import { CfnTopicRule, CfnTopicRuleProps } from '@aws-cdk/aws-iot';
import { IKey, Key, KeyProps } from '@aws-cdk/aws-kms';
import { Role, ServicePrincipal } from '@aws-cdk/aws-iam';
import { Construct } from '@aws-cdk/core';
import { CheckProps, overrideProps } from '@aws-solutions-constructs/core';
import { buildDeadLetterQueue, buildQueue, DefaultCfnTopicRuleProps } from '@aws-solutions-constructs/core';
import * as cdk from '@aws-cdk/core';
import * as sqs from '@aws-cdk/aws-sqs';
import * as iot from '@aws-cdk/aws-iot';
import * as kms from '@aws-cdk/aws-kms';
import * as iam from '@aws-cdk/aws-iam';
import * as defaults from '@aws-solutions-constructs/core';

/**
* @summary The properties for the IotToSqs class.
Expand All @@ -28,21 +27,21 @@ export interface IotToSqsProps {
*
* @default - None
*/
readonly existingQueueObj?: Queue;
readonly existingQueueObj?: sqs.Queue;

/**
* User provided props to override the default props for the SQS queue.
*
* @default - Default props are used
*/
readonly queueProps?: QueueProps;
readonly queueProps?: sqs.QueueProps;

/**
* Optional user provided properties for the dead letter queue
*
* @default - Default props are used
*/
readonly deadLetterQueueProps?: QueueProps;
readonly deadLetterQueueProps?: sqs.QueueProps;

/**
* Whether to deploy a secondary queue to be used as a dead letter queue.
Expand Down Expand Up @@ -71,44 +70,43 @@ export interface IotToSqsProps {
*
* @default - not specified.
*/
readonly encryptionKey?: Key;
readonly encryptionKey?: kms.Key;

/**
* Optional user-provided props to override the default props for the encryption key.
*
* @default - Default props are used.
*/
readonly encryptionKeyProps?: KeyProps;
readonly encryptionKeyProps?: kms.KeyProps;

/**
* User provided CfnTopicRuleProps to override the defaults
*
* @default - None
*/
readonly iotTopicRuleProps: CfnTopicRuleProps;
readonly iotTopicRuleProps: iot.CfnTopicRuleProps;
}

export class IotToSqs extends Construct {
public readonly sqsQueue: Queue;
public readonly deadLetterQueue?: DeadLetterQueue;
public readonly encryptionKey?: IKey;
public readonly iotActionsRole: Role;
public readonly iotTopicRule: CfnTopicRule;
export class IotToSqs extends cdk.Construct {
public readonly sqsQueue: sqs.Queue;
public readonly deadLetterQueue?: sqs.DeadLetterQueue;
public readonly encryptionKey?: kms.IKey;
public readonly iotActionsRole: iam.Role;
public readonly iotTopicRule: iot.CfnTopicRule;

/**
* @summary Constructs a new instance of the IotToSqs class.
* @param {cdk.App} scope - represents the scope for all the resources.
* @param {string} id - this is a a scope-unique id.
* @param {IotToSqsProps} props - user provided props for the construct
* @since 1.110.1
* @access public
*/
constructor(scope: Construct, id: string, props: IotToSqsProps) {
constructor(scope: cdk.Construct, id: string, props: IotToSqsProps) {
super(scope, id);
CheckProps(props);
defaults.CheckProps(props);

// Setup the dead letter queue, if applicable
this.deadLetterQueue = buildDeadLetterQueue(this, {
this.deadLetterQueue = defaults.buildDeadLetterQueue(this, {
existingQueueObj: props.existingQueueObj,
deployDeadLetterQueue: props.deployDeadLetterQueue,
deadLetterQueueProps: props.deadLetterQueueProps,
Expand All @@ -122,7 +120,7 @@ export class IotToSqs extends Construct {
}

// Setup the queue
[this.sqsQueue, this.encryptionKey] = buildQueue(this, 'queue', {
[this.sqsQueue, this.encryptionKey] = defaults.buildQueue(this, 'queue', {
existingQueueObj: props.existingQueueObj,
queueProps: props.queueProps,
deadLetterQueue: this.deadLetterQueue,
Expand All @@ -136,24 +134,24 @@ export class IotToSqs extends Construct {
}

// Role to allow IoT to send messages to the SQS Queue
this.iotActionsRole = new Role(this, 'iot-actions-role', {
assumedBy: new ServicePrincipal('iot.amazonaws.com')
this.iotActionsRole = new iam.Role(this, 'iot-actions-role', {
assumedBy: new iam.ServicePrincipal('iot.amazonaws.com')
});
this.sqsQueue.grantSendMessages(this.iotActionsRole);

if (this.encryptionKey) {
this.encryptionKey.grantEncrypt(this.iotActionsRole);
}

const defaultIotTopicProps = DefaultCfnTopicRuleProps([{
const defaultIotTopicProps = defaults.DefaultCfnTopicRuleProps([{
sqs: {
queueUrl: this.sqsQueue.queueUrl,
roleArn: this.iotActionsRole.roleArn
}
}]);
const iotTopicProps = overrideProps(defaultIotTopicProps, props.iotTopicRuleProps, true);
const iotTopicProps = defaults.overrideProps(defaultIotTopicProps, props.iotTopicRuleProps, true);

// Create the IoT topic rule
this.iotTopicRule = new CfnTopicRule(this, 'IotTopicRule', iotTopicProps);
this.iotTopicRule = new iot.CfnTopicRule(this, 'IotTopicRule', iotTopicProps);
}
}

0 comments on commit 3d0fde1

Please sign in to comment.