Ejemplo n.º 1
0
    public MyStack()
    {
        var console = new Aws.CloudWatch.EventRule("console", new Aws.CloudWatch.EventRuleArgs
        {
            Description  = "Capture each AWS Console Sign In",
            EventPattern = @"{
  ""detail-type"": [
    ""AWS Console Sign In via CloudTrail""
  ]
}

",
        });
        var awsLogins = new Aws.Sns.Topic("awsLogins", new Aws.Sns.TopicArgs
        {
        });
        var sns = new Aws.CloudWatch.EventTarget("sns", new Aws.CloudWatch.EventTargetArgs
        {
            Arn  = awsLogins.Arn,
            Rule = console.Name,
        });
        var snsTopicPolicy = awsLogins.Arn.Apply(arn => Aws.Iam.GetPolicyDocument.InvokeAsync(new Aws.Iam.GetPolicyDocumentArgs
        {
            Statements =
            {
                new Aws.Iam.Inputs.GetPolicyDocumentStatementArgs
                {
                    Actions =
                    {
                        "SNS:Publish",
                    },
                    Effect     = "Allow",
                    Principals =
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalArgs
                        {
                            Identifiers =
                            {
                                "events.amazonaws.com",
                            },
                            Type = "Service",
                        },
                    },
                    Resources =
                    {
                        arn,
                    },
                },
            },
        }));
        var @default = new Aws.Sns.TopicPolicy("default", new Aws.Sns.TopicPolicyArgs
        {
            Arn    = awsLogins.Arn,
            Policy = snsTopicPolicy.Apply(snsTopicPolicy => snsTopicPolicy.Json),
        });
    }
Ejemplo n.º 2
0
    public MyStack()
    {
        var console = new Aws.CloudWatch.EventRule("console", new Aws.CloudWatch.EventRuleArgs
        {
            Description  = "Capture all EC2 scaling events",
            EventPattern = @"{
  ""source"": [
    ""aws.autoscaling""
  ],
  ""detail-type"": [
    ""EC2 Instance Launch Successful"",
    ""EC2 Instance Terminate Successful"",
    ""EC2 Instance Launch Unsuccessful"",
    ""EC2 Instance Terminate Unsuccessful""
  ]
}

",
        });
        var testStream = new Aws.Kinesis.Stream("testStream", new Aws.Kinesis.StreamArgs
        {
            ShardCount = 1,
        });
        var yada = new Aws.CloudWatch.EventTarget("yada", new Aws.CloudWatch.EventTargetArgs
        {
            Arn  = testStream.Arn,
            Rule = console.Name,
            RunCommandTargets =
            {
                new Aws.CloudWatch.Inputs.EventTargetRunCommandTargetArgs
                {
                    Key    = "tag:Name",
                    Values =
                    {
                        "FooBar",
                    },
                },
                new Aws.CloudWatch.Inputs.EventTargetRunCommandTargetArgs
                {
                    Key    = "InstanceIds",
                    Values =
                    {
                        "i-162058cd308bffec2",
                    },
                },
            },
        });
    }