internal EventBridgeLambdaDotnetCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) { // EventBridge Event Bus var eventBus = new EventBus(this, "MyEventBus", new EventBusProps { EventBusName = "MyEventBus" }); // EventBridge Rule var consumerLambdaRule = new Rule(this, "ConsumerLambdaRule", new RuleProps { Description = "Consumer Lambda Event Bus Rule", EventPattern = new EventPattern { Source = new[] { "cdk.myapp" } }, EventBus = eventBus }); // Lambda Function Build Commands var buildCommands = new[] { "cd /asset-input", "export DOTNET_CLI_HOME=\"/tmp/DOTNET_CLI_HOME\"", "export PATH=\"$PATH:/tmp/DOTNET_CLI_HOME/.dotnet/tools\"", "dotnet tool install -g Amazon.Lambda.Tools", "dotnet lambda package -o output.zip", "unzip -o -d /asset-output output.zip" }; // Lambda Function var consumerLambdaHandler = new Function(this, "ConsumerLambda", new FunctionProps { MemorySize = 128, Timeout = Duration.Seconds(10), Runtime = Runtime.DOTNET_CORE_3_1, Code = Code.FromAsset("src/ConsumerLambda", new AssetOptions { Bundling = new BundlingOptions { Image = Runtime.DOTNET_CORE_3_1.BundlingImage, Command = new [] { "bash", "-c", string.Join(" && ", buildCommands) } } }), Handler = "ConsumerLambda::ConsumerLambda.Function::FunctionHandler" }); // Set Lambda Logs Retention and Removal Policy new LogGroup(this, "ConsumerLambdaLogs", new LogGroupProps { LogGroupName = $"/aws/lambda/{consumerLambdaHandler.FunctionName}", RemovalPolicy = RemovalPolicy.DESTROY, Retention = RetentionDays.ONE_DAY }); consumerLambdaRule.AddTarget(new LambdaFunction(consumerLambdaHandler)); }
internal EventBridgeCloudWatchDotnetCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) { // CloudWatch Log Group var cloudWatchLogGroup = new LogGroup(this, "CloudWatchLogs", new LogGroupProps { RemovalPolicy = RemovalPolicy.DESTROY, Retention = RetentionDays.ONE_DAY }); // EventBridge Event Bus var eventBus = new EventBus(this, "MyCloudWatchEventBus", new EventBusProps { EventBusName = "MyCloudWatchEventBus" }); // EventBridge Rule var cloudWatchLogsRule = new Rule(this, "cloudWatchLogsRule", new RuleProps { Description = "CloudWatch Logs Event Bus Rule", EventPattern = new EventPattern { Source = new[] { "cdk.myapp" } }, EventBus = eventBus }); cloudWatchLogsRule.AddTarget(new CloudWatchLogGroup(cloudWatchLogGroup)); // CDK Outputs new CfnOutput(this, "LogGroupName", new CfnOutputProps { Value = cloudWatchLogGroup.LogGroupName !, Description = "CloudWatch Log Group Name" });
internal EventBridgeSqsDotnetCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) { // SQS Queue var myQueue = new Queue(this, "MyQueue"); // Custom EventBridge Bus var eventBus = new EventBus(this, "MySQSEventBus", new EventBusProps { EventBusName = "MySQSEventBus" }); // EventBridge Rule var rule = new Rule(this, "MySQSRule", new RuleProps { Description = "SQS Event Bus Rule", EventPattern = new EventPattern { Source = new[] { "cdk.myapp" } }, EventBus = eventBus }); rule.AddTarget(new SqsQueue(myQueue)); // CDK Outputs new CfnOutput(this, "MySQSUrl", new CfnOutputProps { Value = myQueue.QueueUrl !, Description = "SQS Queue URL" });
internal EventBridgeSnsDotnetCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) { // SNS Topic var mySnsTopic = new Topic(this, "MySNSTopic"); // Custom EventBridge Bus var eventBus = new EventBus(this, "MySNSEventBus", new EventBusProps { EventBusName = "MySNSEventBus" }); // EventBridge Rule var rule = new Rule(this, "MySNSRule", new RuleProps { Description = "SNS Event Bus Rule", EventPattern = new EventPattern { Source = new[] { "cdk.myapp" } }, EventBus = eventBus }); rule.AddTarget(new SnsTopic(mySnsTopic)); // CDK Outputs new CfnOutput(this, "SNSTopicName", new CfnOutputProps { Value = mySnsTopic.TopicName !, Description = "SNS topic name" });