@gradientedge/cdk-utils 5.5.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/lib/manager/aws/lambda-manager.js +6 -0
- package/dist/src/lib/manager/aws/sqs-manager.d.ts +18 -3
- package/dist/src/lib/manager/aws/sqs-manager.js +45 -6
- package/dist/src/lib/types/aws/index.d.ts +4 -0
- package/package.json +1 -1
- package/src/lib/manager/aws/lambda-manager.ts +9 -0
- package/src/lib/manager/aws/sqs-manager.ts +57 -11
- package/src/lib/types/aws/index.ts +4 -0
|
@@ -87,6 +87,11 @@ class LambdaManager {
|
|
|
87
87
|
if (!props)
|
|
88
88
|
throw `Lambda props undefined`;
|
|
89
89
|
const functionName = `${props.functionName}-${scope.props.stage}`;
|
|
90
|
+
let deadLetterQueue;
|
|
91
|
+
if (props.deadLetterQueueEnabled && props.dlq) {
|
|
92
|
+
const redriveQueue = scope.sqsManager.createRedriveQueueForLambda(`${id}-rdq`, scope, props);
|
|
93
|
+
deadLetterQueue = scope.sqsManager.createDeadLetterQueueForLambda(`${id}-dlq`, scope, props, redriveQueue);
|
|
94
|
+
}
|
|
90
95
|
const lambdaFunction = new lambda.Function(scope, `${id}`, {
|
|
91
96
|
...props,
|
|
92
97
|
...{
|
|
@@ -95,6 +100,7 @@ class LambdaManager {
|
|
|
95
100
|
handler: handler || 'index.lambda_handler',
|
|
96
101
|
runtime: LambdaManager.NODEJS_RUNTIME,
|
|
97
102
|
code: code,
|
|
103
|
+
deadLetterQueue: deadLetterQueue,
|
|
98
104
|
environment: {
|
|
99
105
|
REGION: scope.props.region,
|
|
100
106
|
...environment,
|
|
@@ -16,7 +16,7 @@ import * as types from '../../types';
|
|
|
16
16
|
* constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
|
|
17
17
|
* super(parent, id, props)
|
|
18
18
|
* this.props = props
|
|
19
|
-
* this.sqsManager.
|
|
19
|
+
* this.sqsManager.createQueue('MySqs', this, {...})
|
|
20
20
|
* }
|
|
21
21
|
* }
|
|
22
22
|
*
|
|
@@ -28,7 +28,22 @@ export declare class SqsManager {
|
|
|
28
28
|
* @param {string} id scoped id of the resource
|
|
29
29
|
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
30
30
|
* @param {types.QueueProps} props
|
|
31
|
-
* @param {sqs.
|
|
31
|
+
* @param {sqs.IQueue} deadLetterQueue
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
createQueue(id: string, scope: common.CommonConstruct, props: types.QueueProps, deadLetterQueue?: sqs.IQueue): cdk.aws_sqs.Queue;
|
|
34
|
+
/**
|
|
35
|
+
* @summary Method to create a redrive queue for a lambda function
|
|
36
|
+
* @param {string} id scoped id of the resource
|
|
37
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
38
|
+
* @param {types.LambdaProps} props the lambda properties
|
|
39
|
+
*/
|
|
40
|
+
createRedriveQueueForLambda(id: string, scope: common.CommonConstruct, props: types.LambdaProps): cdk.aws_sqs.Queue;
|
|
41
|
+
/**
|
|
42
|
+
* @summary Method to create a dead letter queue for a lambda function
|
|
43
|
+
* @param {string} id scoped id of the resource
|
|
44
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
45
|
+
* @param {types.LambdaProps} props the lambda properties
|
|
46
|
+
* @param {sqs.IQueue} deadLetterQueue
|
|
47
|
+
*/
|
|
48
|
+
createDeadLetterQueueForLambda(id: string, scope: common.CommonConstruct, props: types.LambdaProps, deadLetterQueue: sqs.IQueue): cdk.aws_sqs.Queue;
|
|
34
49
|
}
|
|
@@ -41,7 +41,7 @@ const utils = __importStar(require("../../utils"));
|
|
|
41
41
|
* constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
|
|
42
42
|
* super(parent, id, props)
|
|
43
43
|
* this.props = props
|
|
44
|
-
* this.sqsManager.
|
|
44
|
+
* this.sqsManager.createQueue('MySqs', this, {...})
|
|
45
45
|
* }
|
|
46
46
|
* }
|
|
47
47
|
*
|
|
@@ -53,9 +53,9 @@ class SqsManager {
|
|
|
53
53
|
* @param {string} id scoped id of the resource
|
|
54
54
|
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
55
55
|
* @param {types.QueueProps} props
|
|
56
|
-
* @param {sqs.
|
|
56
|
+
* @param {sqs.IQueue} deadLetterQueue
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
createQueue(id, scope, props, deadLetterQueue) {
|
|
59
59
|
if (!props)
|
|
60
60
|
throw `Queue props undefined`;
|
|
61
61
|
const queue = new sqs.Queue(scope, id, {
|
|
@@ -64,7 +64,12 @@ class SqsManager {
|
|
|
64
64
|
receiveMessageWaitTime: cdk.Duration.seconds(props.receiveMessageWaitTimeInSecs),
|
|
65
65
|
contentBasedDeduplication: props.contentBasedDeduplication,
|
|
66
66
|
dataKeyReuse: cdk.Duration.seconds(props.dataKeyReuseInSecs),
|
|
67
|
-
deadLetterQueue: deadLetterQueue
|
|
67
|
+
deadLetterQueue: !deadLetterQueue
|
|
68
|
+
? undefined
|
|
69
|
+
: {
|
|
70
|
+
queue: deadLetterQueue,
|
|
71
|
+
maxReceiveCount: props.maxReceiveCount,
|
|
72
|
+
},
|
|
68
73
|
deduplicationScope: props.deduplicationScope,
|
|
69
74
|
deliveryDelay: cdk.Duration.seconds(props.deliveryDelayInSecs),
|
|
70
75
|
encryption: props.encryption,
|
|
@@ -72,13 +77,47 @@ class SqsManager {
|
|
|
72
77
|
fifo: props.fifo,
|
|
73
78
|
fifoThroughputLimit: props.fifoThroughputLimit,
|
|
74
79
|
maxMessageSizeBytes: props.maxMessageSizeBytes,
|
|
75
|
-
removalPolicy: props.removalPolicy,
|
|
76
|
-
retentionPeriod: props.
|
|
80
|
+
removalPolicy: props.removalPolicy ?? cdk.RemovalPolicy.DESTROY,
|
|
81
|
+
retentionPeriod: cdk.Duration.days(props.retentionInDays),
|
|
77
82
|
});
|
|
78
83
|
utils.createCfnOutput(`${id}-queueArn`, scope, queue.queueArn);
|
|
79
84
|
utils.createCfnOutput(`${id}-queueName`, scope, queue.queueName);
|
|
80
85
|
utils.createCfnOutput(`${id}-queueUrl`, scope, queue.queueUrl);
|
|
81
86
|
return queue;
|
|
82
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* @summary Method to create a redrive queue for a lambda function
|
|
90
|
+
* @param {string} id scoped id of the resource
|
|
91
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
92
|
+
* @param {types.LambdaProps} props the lambda properties
|
|
93
|
+
*/
|
|
94
|
+
createRedriveQueueForLambda(id, scope, props) {
|
|
95
|
+
if (!props.dlq || !props.redriveq)
|
|
96
|
+
throw `Redrive queue props for Lambda undefined`;
|
|
97
|
+
return this.createQueue(`${id}`, scope, {
|
|
98
|
+
...props.dlq,
|
|
99
|
+
...props.redriveq,
|
|
100
|
+
...{
|
|
101
|
+
queueName: `${props.functionName}-redriveq-${scope.props.stage}`,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @summary Method to create a dead letter queue for a lambda function
|
|
107
|
+
* @param {string} id scoped id of the resource
|
|
108
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
109
|
+
* @param {types.LambdaProps} props the lambda properties
|
|
110
|
+
* @param {sqs.IQueue} deadLetterQueue
|
|
111
|
+
*/
|
|
112
|
+
createDeadLetterQueueForLambda(id, scope, props, deadLetterQueue) {
|
|
113
|
+
if (!props.dlq)
|
|
114
|
+
throw `Dead letter queue props for Lambda undefined`;
|
|
115
|
+
return this.createQueue(`${id}`, scope, {
|
|
116
|
+
...props.dlq,
|
|
117
|
+
...{
|
|
118
|
+
queueName: `${props.functionName}-dlq-${scope.props.stage}`,
|
|
119
|
+
},
|
|
120
|
+
}, deadLetterQueue);
|
|
121
|
+
}
|
|
83
122
|
}
|
|
84
123
|
exports.SqsManager = SqsManager;
|
|
@@ -491,6 +491,8 @@ export interface EventBusProps extends events.EventBusProps {
|
|
|
491
491
|
* @subcategory Properties
|
|
492
492
|
*/
|
|
493
493
|
export interface LambdaProps extends lambda.FunctionProps {
|
|
494
|
+
dlq?: QueueProps;
|
|
495
|
+
redriveq?: QueueProps;
|
|
494
496
|
timeoutInSecs?: number;
|
|
495
497
|
}
|
|
496
498
|
/**
|
|
@@ -575,9 +577,11 @@ export interface ElastiCacheProps extends elasticache.CfnCacheClusterProps {
|
|
|
575
577
|
* @subcategory Properties
|
|
576
578
|
*/
|
|
577
579
|
export interface QueueProps extends sqs.QueueProps {
|
|
580
|
+
maxReceiveCount: number;
|
|
578
581
|
visibilityTimeoutInSecs: number;
|
|
579
582
|
receiveMessageWaitTimeInSecs: number;
|
|
580
583
|
dataKeyReuseInSecs: number;
|
|
581
584
|
deliveryDelayInSecs: number;
|
|
585
|
+
retentionInDays: number;
|
|
582
586
|
}
|
|
583
587
|
export {};
|
package/package.json
CHANGED
|
@@ -30,6 +30,7 @@ import { CloudFrontManager } from './cloudfront-manager'
|
|
|
30
30
|
*/
|
|
31
31
|
export class LambdaManager {
|
|
32
32
|
public static NODEJS_RUNTIME = lambda.Runtime.NODEJS_16_X
|
|
33
|
+
|
|
33
34
|
/**
|
|
34
35
|
* @summary Method to create a lambda layer (nodejs)
|
|
35
36
|
* @param {string} id scoped id of the resource
|
|
@@ -83,6 +84,13 @@ export class LambdaManager {
|
|
|
83
84
|
if (!props) throw `Lambda props undefined`
|
|
84
85
|
|
|
85
86
|
const functionName = `${props.functionName}-${scope.props.stage}`
|
|
87
|
+
|
|
88
|
+
let deadLetterQueue
|
|
89
|
+
if (props.deadLetterQueueEnabled && props.dlq) {
|
|
90
|
+
const redriveQueue = scope.sqsManager.createRedriveQueueForLambda(`${id}-rdq`, scope, props)
|
|
91
|
+
deadLetterQueue = scope.sqsManager.createDeadLetterQueueForLambda(`${id}-dlq`, scope, props, redriveQueue)
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
const lambdaFunction = new lambda.Function(scope, `${id}`, {
|
|
87
95
|
...props,
|
|
88
96
|
...{
|
|
@@ -91,6 +99,7 @@ export class LambdaManager {
|
|
|
91
99
|
handler: handler || 'index.lambda_handler',
|
|
92
100
|
runtime: LambdaManager.NODEJS_RUNTIME,
|
|
93
101
|
code: code,
|
|
102
|
+
deadLetterQueue: deadLetterQueue,
|
|
94
103
|
environment: {
|
|
95
104
|
REGION: scope.props.region,
|
|
96
105
|
...environment,
|
|
@@ -18,7 +18,7 @@ import * as utils from '../../utils'
|
|
|
18
18
|
* constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
|
|
19
19
|
* super(parent, id, props)
|
|
20
20
|
* this.props = props
|
|
21
|
-
* this.sqsManager.
|
|
21
|
+
* this.sqsManager.createQueue('MySqs', this, {...})
|
|
22
22
|
* }
|
|
23
23
|
* }
|
|
24
24
|
*
|
|
@@ -30,14 +30,9 @@ export class SqsManager {
|
|
|
30
30
|
* @param {string} id scoped id of the resource
|
|
31
31
|
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
32
32
|
* @param {types.QueueProps} props
|
|
33
|
-
* @param {sqs.
|
|
33
|
+
* @param {sqs.IQueue} deadLetterQueue
|
|
34
34
|
*/
|
|
35
|
-
public
|
|
36
|
-
id: string,
|
|
37
|
-
scope: common.CommonConstruct,
|
|
38
|
-
props: types.QueueProps,
|
|
39
|
-
deadLetterQueue?: sqs.DeadLetterQueue
|
|
40
|
-
) {
|
|
35
|
+
public createQueue(id: string, scope: common.CommonConstruct, props: types.QueueProps, deadLetterQueue?: sqs.IQueue) {
|
|
41
36
|
if (!props) throw `Queue props undefined`
|
|
42
37
|
|
|
43
38
|
const queue = new sqs.Queue(scope, id, {
|
|
@@ -46,7 +41,12 @@ export class SqsManager {
|
|
|
46
41
|
receiveMessageWaitTime: cdk.Duration.seconds(props.receiveMessageWaitTimeInSecs),
|
|
47
42
|
contentBasedDeduplication: props.contentBasedDeduplication,
|
|
48
43
|
dataKeyReuse: cdk.Duration.seconds(props.dataKeyReuseInSecs),
|
|
49
|
-
deadLetterQueue: deadLetterQueue
|
|
44
|
+
deadLetterQueue: !deadLetterQueue
|
|
45
|
+
? undefined
|
|
46
|
+
: {
|
|
47
|
+
queue: deadLetterQueue,
|
|
48
|
+
maxReceiveCount: props.maxReceiveCount,
|
|
49
|
+
},
|
|
50
50
|
deduplicationScope: props.deduplicationScope,
|
|
51
51
|
deliveryDelay: cdk.Duration.seconds(props.deliveryDelayInSecs),
|
|
52
52
|
encryption: props.encryption,
|
|
@@ -54,8 +54,8 @@ export class SqsManager {
|
|
|
54
54
|
fifo: props.fifo,
|
|
55
55
|
fifoThroughputLimit: props.fifoThroughputLimit,
|
|
56
56
|
maxMessageSizeBytes: props.maxMessageSizeBytes,
|
|
57
|
-
removalPolicy: props.removalPolicy,
|
|
58
|
-
retentionPeriod: props.
|
|
57
|
+
removalPolicy: props.removalPolicy ?? cdk.RemovalPolicy.DESTROY,
|
|
58
|
+
retentionPeriod: cdk.Duration.days(props.retentionInDays),
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
utils.createCfnOutput(`${id}-queueArn`, scope, queue.queueArn)
|
|
@@ -64,4 +64,50 @@ export class SqsManager {
|
|
|
64
64
|
|
|
65
65
|
return queue
|
|
66
66
|
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @summary Method to create a redrive queue for a lambda function
|
|
70
|
+
* @param {string} id scoped id of the resource
|
|
71
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
72
|
+
* @param {types.LambdaProps} props the lambda properties
|
|
73
|
+
*/
|
|
74
|
+
public createRedriveQueueForLambda(id: string, scope: common.CommonConstruct, props: types.LambdaProps) {
|
|
75
|
+
if (!props.dlq || !props.redriveq) throw `Redrive queue props for Lambda undefined`
|
|
76
|
+
|
|
77
|
+
return this.createQueue(`${id}`, scope, {
|
|
78
|
+
...props.dlq,
|
|
79
|
+
...props.redriveq,
|
|
80
|
+
...{
|
|
81
|
+
queueName: `${props.functionName}-redriveq-${scope.props.stage}`,
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @summary Method to create a dead letter queue for a lambda function
|
|
88
|
+
* @param {string} id scoped id of the resource
|
|
89
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
90
|
+
* @param {types.LambdaProps} props the lambda properties
|
|
91
|
+
* @param {sqs.IQueue} deadLetterQueue
|
|
92
|
+
*/
|
|
93
|
+
public createDeadLetterQueueForLambda(
|
|
94
|
+
id: string,
|
|
95
|
+
scope: common.CommonConstruct,
|
|
96
|
+
props: types.LambdaProps,
|
|
97
|
+
deadLetterQueue: sqs.IQueue
|
|
98
|
+
) {
|
|
99
|
+
if (!props.dlq) throw `Dead letter queue props for Lambda undefined`
|
|
100
|
+
|
|
101
|
+
return this.createQueue(
|
|
102
|
+
`${id}`,
|
|
103
|
+
scope,
|
|
104
|
+
{
|
|
105
|
+
...props.dlq,
|
|
106
|
+
...{
|
|
107
|
+
queueName: `${props.functionName}-dlq-${scope.props.stage}`,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
deadLetterQueue
|
|
111
|
+
)
|
|
112
|
+
}
|
|
67
113
|
}
|
|
@@ -524,6 +524,8 @@ export interface EventBusProps extends events.EventBusProps {}
|
|
|
524
524
|
* @subcategory Properties
|
|
525
525
|
*/
|
|
526
526
|
export interface LambdaProps extends lambda.FunctionProps {
|
|
527
|
+
dlq?: QueueProps
|
|
528
|
+
redriveq?: QueueProps
|
|
527
529
|
timeoutInSecs?: number
|
|
528
530
|
}
|
|
529
531
|
|
|
@@ -614,8 +616,10 @@ export interface ElastiCacheProps extends elasticache.CfnCacheClusterProps {}
|
|
|
614
616
|
* @subcategory Properties
|
|
615
617
|
*/
|
|
616
618
|
export interface QueueProps extends sqs.QueueProps {
|
|
619
|
+
maxReceiveCount: number
|
|
617
620
|
visibilityTimeoutInSecs: number
|
|
618
621
|
receiveMessageWaitTimeInSecs: number
|
|
619
622
|
dataKeyReuseInSecs: number
|
|
620
623
|
deliveryDelayInSecs: number
|
|
624
|
+
retentionInDays: number
|
|
621
625
|
}
|