Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logRetention: logs.RetentionDays.TWO_WEEKS,
timeout: cdk.Duration.seconds(30),
memorySize: 128,
environment: {
"ALARM_SNS": config['alarm_sns_arn']
},
});
// Add priv to publish the events so the alarms can be forwarded
alarm_forwarder.addToRolePolicy(new iam.PolicyStatement({
resources: [config['alarm_sns_arn']],
actions: ['sns:Publish']
}));
// Connect the SNS to the Lambda
sns_topic.addSubscription(new sns_subscription.LambdaSubscription(alarm_forwarder));
}
}
logRetention: logs.RetentionDays.TWO_WEEKS,
timeout: cdk.Duration.seconds(30),
memorySize: 128,
environment: {
"ALARM_SNS": config['alarm_sns_arn']
},
});
// Add priv to publish the events so the alarms can be forwarded
alarm_forwarder.addToRolePolicy(new iam.PolicyStatement({
resources: [config['alarm_sns_arn']],
actions: ['sns:Publish']
}));
// Connect the SNS to the Lambda
sns_topic.addSubscription(new sns_subscription.LambdaSubscription(alarm_forwarder));
}
}
timeToLiveAttribute: "expires_at",
});
// ----------------------------------------------------------------
// Messaging Channels
this.alertTopic = new sns.Topic(this, "alertTopic");
this.taskTopic = new sns.Topic(this, "taskTopic");
this.contentTopic = new sns.Topic(this, "contentTopic");
this.attributeTopic = new sns.Topic(this, "attributeTopic");
this.reportTopic = new sns.Topic(this, "reportTopic");
const alertQueueTimeout = cdk.Duration.seconds(30);
this.alertQueue = new sqs.Queue(this, "alertQueue", {
visibilityTimeout: alertQueueTimeout,
});
this.alertTopic.addSubscription(new SqsSubscription(this.alertQueue));
const contentQueueTimeout = cdk.Duration.seconds(30);
this.contentQueue = new sqs.Queue(this, "contentQueue", {
visibilityTimeout: contentQueueTimeout,
});
const attributeQueueTimeout = cdk.Duration.seconds(30);
this.attributeQueue = new sqs.Queue(this, "attributeQueue", {
visibilityTimeout: attributeQueueTimeout,
});
// ----------------------------------------------------------------
// Lambda Functions
const baseEnvVars = {
TASK_TOPIC: this.taskTopic.topicArn,
REPORT_TOPIC: this.reportTopic.topicArn,
const approvalRequester = new Function(
scope,
'SlackApprovalRequesterFunction',
{
runtime: Runtime.NODEJS_10_X,
handler: 'lib/approval-requester.handler',
code: Code.asset(
path.join(__dirname, '..', 'lambda', 'bundle.zip'),
),
environment,
},
);
const topic = new Topic(scope, 'SlackApprovalTopic');
topic.grantPublish(options.role);
topic.addSubscription(new LambdaSubscription(approvalRequester));
const approvalHandler = new Function(
scope,
'SlackApprovalHandlerFunction',
{
runtime: Runtime.NODEJS_10_X,
handler: 'lib/approval-handler.handler',
code: Code.fromAsset(
path.join(__dirname, '..', 'lambda', 'bundle.zip'),
),
environment,
},
);
const api = new RestApi(scope, 'SlackApprovalApi');
api.root.addProxy({
public bind(scope: Construct, lifecycleHook: autoscaling.ILifecycleHook): autoscaling.LifecycleHookTargetConfig {
const topic = new sns.Topic(scope, 'Topic');
topic.addSubscription(new subs.LambdaSubscription(this.fn));
return new TopicHook(topic).bind(scope, lifecycleHook);
}
}
public bind(target: lambda.IFunction) {
this.topic.addSubscription(new subs.LambdaSubscription(target));
}
}
protected bound(scope: cdk.Construct, _stage: codepipeline.IStage, options: codepipeline.ActionBindOptions):
codepipeline.ActionConfig {
if (this.props.notificationTopic) {
this._notificationTopic = this.props.notificationTopic;
} else if ((this.props.notifyEmails || []).length > 0) {
this._notificationTopic = new sns.Topic(scope, 'TopicResource');
}
if (this._notificationTopic) {
this._notificationTopic.grantPublish(options.role);
for (const notifyEmail of this.props.notifyEmails || []) {
this._notificationTopic.addSubscription(new subs.EmailSubscription(notifyEmail));
}
}
return {
configuration: this._notificationTopic
? {
NotificationArn: this._notificationTopic.topicArn,
CustomData: this.props.additionalInformation,
}
: undefined,
};
}
}