LoginSignup
1
1

More than 5 years have passed since last update.

CloudFormationテンプレート(JSON) - AWS Config 設定

Last updated at Posted at 2018-01-15

#1. 概要

#2. 各リソースメモ

#3. JSONテンプレート

AWSConfig.json

{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "AWS Config",
    "Resources" : {
        "S3Bucket" : {
            "Type" : "AWS::S3::Bucket",
            "Properties" : {
                "BucketName" : { "Fn::Join" : [ "", [ "awsconfig-", { "Ref" : "AWS::AccountId" } ] ] }
            }
        },
        "S3BucketPolicy" : {
            "Type" : "AWS::S3::BucketPolicy",
            "Properties" : {
                "Bucket" : { "Ref": "S3Bucket"},
                "PolicyDocument" : {
                    "Version" : "2012-10-17",
                    "Statement" : [
                        {
                            "Sid" : "AWSConfigBucketPermissionsCheck",
                            "Effect" : "Allow",
                            "Principal" : {
                                "Service" : [
                                    "config.amazonaws.com"
                                ]
                            },
                            "Action" : "s3:GetBucketAcl",
                            "Resource" : { "Fn::Join" : [ "", [ "arn:aws:s3:::awsconfig-", { "Ref" : "AWS::AccountId" } ] ] }
                        },
                        {
                            "Sid" : " AWSConfigBucketDelivery",
                            "Effect" : "Allow",
                            "Principal" : {
                                "Service" : [
                                    "config.amazonaws.com"
                                ]
                            },
                            "Action" : "s3:PutObject",
                            "Resource" : { "Fn::Join" : [ "", [ "arn:aws:s3:::awsconfig-", { "Ref" : "AWS::AccountId" }, "/AWSLogs/", { "Ref" : "AWS::AccountId" }, "/Config/*" ] ] },
                            "Condition" : {
                                "StringEquals" : {
                                    "s3:x-amz-acl" : "bucket-owner-full-control"
                                }
                            }
                        }
                    ]
                }
            }
        },
        "SNSTopic" : {
            "Type" : "AWS::SNS::Topic",
            "Properties" : {
                "DisplayName" : "AWS Config Notification Topic",
                "TopicName" : "awsconfig"
            }
        },
        "SNSSubscription" : {
            "Type" : "AWS::SNS::Subscription",
            "Properties" : {
                "Endpoint" : "test@example.com",
                "Protocol" : "email",
                "TopicArn" : { "Ref" : "SNSTopic"}
            }
        },
        "IAMRole" : {
            "Type" : "AWS::IAM::Role",
            "Properties" : {
                "AssumeRolePolicyDocument" : {
                    "Version" : "2012-10-17",
                    "Statement" : [
                        {
                            "Sid" : "",
                            "Effect" : "Allow",
                            "Principal" : {
                                "Service" : "config.amazonaws.com"
                            },
                            "Action" : "sts:AssumeRole"
                        }
                    ]
                },
                "ManagedPolicyArns" : [ "arn:aws:iam::aws:policy/service-role/AWSConfigRole" ],
                "Path" : "/",
                "Policies" : [
                    {
                        "PolicyName" : "awsconfig",
                        "PolicyDocument" : {
                            "Version" : "2012-10-17",
                            "Statement" : [
                                {
                                    "Effect" : "Allow",
                                    "Action" : [
                                        "s3:PutObject*"
                                    ],
                                    "Resource" : { "Fn::Join" : [ "", [ "arn:aws:s3:::awsconfig-", { "Ref" : "AWS::AccountId" }, "/AWSLogs/", { "Ref" : "AWS::AccountId" }, "/*" ] ] },
                                    "Condition" : {
                                        "StringLike" : {
                                            "s3:x-amz-acl" : "bucket-owner-full-control"
                                        }
                                    }
                                },
                                {
                                    "Effect" : "Allow",
                                    "Action" : [ "s3:GetBucketAcl" ],
                                    "Resource" : { "Fn::Join" : [ "", [ "arn:aws:s3:::awsconfig-", { "Ref" : "AWS::AccountId" } ] ] }
                                },
                                {
                                    "Effect" : "Allow",
                                    "Action" : "sns:Publish",
                                    "Resource" : "arn:aws:sns:ap-northeast-1:777813037810:awsconfig",
                                    "Resource" : { "Fn::Join" : [ "", [ "arn:aws:sns:ap-northeast-1:", { "Ref" : "AWS::AccountId" }, ":", { "Fn::GetAtt" : [ "SNSTopic", "TopicName" ] } ] ] }
                                }
                            ]
                        }
                    }
                ],
                "RoleName" : "awsconfig"
            }
        },
        "ConfigConfigurationRecorder" : {
            "Type" : "AWS::Config::ConfigurationRecorder",
            "DependsOn" : [ "S3Bucket", "SNSTopic" ],
            "Properties" : {
                "Name" : { "Fn::Join" : [ "", [ "awsconfig-", { "Ref" : "AWS::AccountId" } ] ] },
                "RecordingGroup" : {
                    "AllSupported" : true,
                    "ResourceTypes" : [],
                    "IncludeGlobalResourceTypes" : true
                },
                "RoleARN" : { "Fn::GetAtt" : [ "IAMRole", "Arn" ] }
            }
        },
        "ConfigDeliveryChannel" : {
            "Type" : "AWS::Config::DeliveryChannel",
            "DependsOn" : [ "S3Bucket", "SNSTopic" ],
            "Properties" : {
                "Name" : { "Fn::Join" : [ "", [ "awsconfig-", { "Ref" : "AWS::AccountId" } ] ] },
                "S3BucketName" : { "Ref" : "S3Bucket" },
                "SnsTopicARN" : { "Ref" : "SNSTopic" }
          }
        }
    },
    "Outputs" : {
        "S3Bucket" : {
            "Description" : "S3 Bucket Name",
            "Value" : { "Ref" : S3Bucket }
        },
        "SNSTopic" : {
            "Description" : "SNS Topic Name",
            "Value" : { "Fn::GetAtt" : [ "SNSTopic", "TopicName" ] }
        },
        "IAMRole" : {
            "Description" : "IAM Role Name",
            "Value" : { "Ref" : IAMRole }
        },
        "ConfigConfigurationRecorder" : {
            "Description" : "Config ConfigurationRecorder Name",
            "Value" : { "Ref" : ConfigConfigurationRecorder }
        },
        "ConfigDeliveryChannel" : {
            "Description" : "Config DeliveryChannel Name",
            "Value" : { "Ref" : ConfigDeliveryChannel }
        }
    }
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1