Created
January 21, 2021 09:11
-
-
Save MasahiroKawahara/ad0e010e0a238932c4d2e5db55afc162 to your computer and use it in GitHub Desktop.
【AWS Config】EC2インスタンスに特定アプリケーションがインストールされているかチェックして通知する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Parameters: | |
ApplicationNames: | |
Description: "Comma-separated list of application names. Optionally, specify versions appended with ':' (for example, 'Chrome:0.5.3, Firefox')." | |
Type: String | |
Default: "[Enter Application name]" | |
SnsTopicArn: | |
Description: "SNS topic ARN to be used in the remediation actions." | |
Type: String | |
Default: "[Enter SNS topic ARN]" | |
Resources: | |
# 修復アクション(SSMオートメーション)のための IAMロール | |
IamRole: | |
Type: AWS::IAM::Role | |
Properties: | |
RoleName: ssm-automation-role-for-ec2-applications-required | |
Description: "role for ssm automation: ec2 managedinstance applications required" | |
AssumeRolePolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
- Effect: "Allow" | |
Principal: | |
Service: "ssm.amazonaws.com" | |
Action: "sts:AssumeRole" | |
Policies: | |
- PolicyName: sns-policy | |
PolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
Effect: "Allow" | |
Action: "sns:Publish" | |
Resource: "*" | |
# Configルール | |
ConfigRule: | |
Type: AWS::Config::ConfigRule | |
Properties: | |
ConfigRuleName: ec2-managedinstance-applications-required | |
Description: "すべての指定されたアプリケーションがインスタンスにインストールされていることを確認します。オプションで、使用可能な最小バージョンを指定します。新しいバージョンはブラックリストに記載されていません。オプションで、プラットフォームを指定し、そのプラットフォームを実行しているインスタンスにのみルールを適用します。" | |
Source: | |
Owner: AWS | |
SourceIdentifier: EC2_MANAGEDINSTANCE_APPLICATIONS_REQUIRED | |
Scope: | |
ComplianceResourceTypes: | |
- "AWS::SSM::ManagedInstanceInventory" | |
InputParameters: | |
applicationNames: !Ref ApplicationNames | |
# platformType: (option) | |
# 修復アクション(SSMオートメーション) | |
RemediationConfiguration: | |
Type: AWS::Config::RemediationConfiguration | |
Properties: | |
Automatic: true | |
ConfigRuleName: !Ref ConfigRule | |
MaximumAutomaticAttempts: 1 | |
RetryAttemptSeconds: 60 | |
TargetId: "AWS-PublishSNSNotification" | |
TargetType: "SSM_DOCUMENT" | |
TargetVersion: "1" | |
Parameters: | |
AutomationAssumeRole: | |
StaticValue: | |
Values: | |
- !GetAtt [IamRole, "Arn"] | |
TopicArn: | |
StaticValue: | |
Values: | |
- !Ref SnsTopicArn | |
Message: | |
ResourceValue: | |
Value: RESOURCE_ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment