Skip to content

Commit

Permalink
chore(sqs): use ICfnQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc committed Dec 1, 2023
1 parent 59ca33b commit 2968f0f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
20 changes: 19 additions & 1 deletion packages/aws-cdk-lib/aws-sqs/lib/queue-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { QueuePolicy } from './policy';
import * as iam from '../../aws-iam';
import * as kms from '../../aws-kms';
import { IResource, Resource, ResourceProps } from '../../core';
import { ICfnQueue } from './sqs.generated';

/**
* Represents an SQS queue
*/
export interface IQueue extends IResource {
export interface IQueue extends IResource, ICfnQueue {
/**
* The ARN of this queue
* @attribute
Expand Down Expand Up @@ -105,14 +106,31 @@ export interface IQueue extends IResource {
* Reference to a new or existing Amazon SQS queue
*/
export abstract class QueueBase extends Resource implements IQueue {
/**
* The ARN of this queue
*
* @attribute
*/
public abstract readonly attrArn: string;

/**
* The ARN of this queue
*
* @deprecated use attrArn
*/
public abstract readonly queueArn: string;

/**
* The URL of this queue
*
* @attribute
*/
public abstract readonly attrQueueUrl: string;

/**
* The URL of this queue
*
* @deprecated use attrQueueUrl
*/
public abstract readonly queueUrl: string;

Expand Down
37 changes: 29 additions & 8 deletions packages/aws-cdk-lib/aws-sqs/lib/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface QueueProps {
*
* If specified and this is a FIFO queue, must end in the string '.fifo'.
*
* @default CloudFormation-generated name
* @default - CloudFormation generated name
*/
readonly queueName?: string;

Expand Down Expand Up @@ -78,7 +78,7 @@ export interface QueueProps {
/**
* Send messages to this queue if they were unsuccessfully dequeued a number of times.
*
* @default no dead-letter queue
* @default - no dead-letter queue
*/
readonly deadLetterQueue?: DeadLetterQueue;

Expand All @@ -102,7 +102,7 @@ export interface QueueProps {
* If the 'encryptionMasterKey' property is set, 'encryption' type will be
* implicitly set to "KMS".
*
* @default If encryption is set to KMS and not specified, a key will be created.
* @default - If encryption is set to KMS and not specified, a key will be created.
*/
readonly encryptionMasterKey?: kms.IKey;

Expand Down Expand Up @@ -227,7 +227,6 @@ export enum FifoThroughputLimit {
* A new Amazon SQS queue
*/
export class Queue extends QueueBase {

/**
* Import an existing SQS queue provided an ARN
*
Expand All @@ -249,8 +248,10 @@ export class Queue extends QueueBase {
const queueUrl = attrs.queueUrl || `https://sqs.${parsedArn.region}.${stack.urlSuffix}/${parsedArn.account}/${queueName}`;

class Import extends QueueBase {
public readonly queueArn = attrs.queueArn; // arn:aws:sqs:us-east-1:123456789012:queue1
public readonly queueUrl = queueUrl;
public readonly attrArn = attrs.queueArn; // arn:aws:sqs:us-east-1:123456789012:queue1
public readonly queueArn = this.attrArn;
public readonly attrQueueUrl = queueUrl;
public readonly queueUrl = this.attrQueueUrl;
public readonly queueName = queueName;
public readonly encryptionMasterKey = attrs.keyArn
? kms.Key.fromKeyArn(this, 'Key', attrs.keyArn)
Expand Down Expand Up @@ -289,6 +290,15 @@ export class Queue extends QueueBase {

/**
* The ARN of this queue
*
* @attribute
*/
public readonly attrArn: string;

/**
* The ARN of this queue
*
* @deprecated use attrArn
*/
public readonly queueArn: string;

Expand All @@ -299,6 +309,15 @@ export class Queue extends QueueBase {

/**
* The URL of this queue
*
* @attribute
*/
public readonly attrQueueUrl: string;

/**
* The URL of this queue
*
* @deprecated use attrQUeueUrl
*/
public readonly queueUrl: string;

Expand Down Expand Up @@ -356,13 +375,15 @@ export class Queue extends QueueBase {
});
queue.applyRemovalPolicy(props.removalPolicy ?? RemovalPolicy.DESTROY);

this.queueArn = this.getResourceArnAttribute(queue.attrArn, {
this.attrArn = this.getResourceArnAttribute(queue.attrArn, {
service: 'sqs',
resource: this.physicalName,
});
this.queueArn = this.attrArn;
this.queueName = this.getResourceNameAttribute(queue.attrQueueName);
this.encryptionMasterKey = encryptionMasterKey;
this.queueUrl = queue.ref;
this.attrQueueUrl = queue.ref;
this.queueUrl = this.attrQueueUrl;
this.deadLetterQueue = props.deadLetterQueue;
this.encryptionType = encryptionType;

Expand Down

0 comments on commit 2968f0f

Please sign in to comment.