{"id":17319,"date":"2019-10-29T21:00:19","date_gmt":"2019-10-29T12:00:19","guid":{"rendered":"http:\/\/www.skyarch.net\/blog\/?p=17319"},"modified":"2019-10-29T17:46:47","modified_gmt":"2019-10-29T08:46:47","slug":"aws-systems-manager-%e3%82%aa%e3%83%bc%e3%83%88%e3%83%a1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ab%e3%82%88%e3%82%8b-autoscaling-%e3%82%b0%e3%83%ab%e3%83%bc%e3%83%97%e3%81%aeami%e6%9b%b4%e6%96%b0","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/aws-systems-manager-%e3%82%aa%e3%83%bc%e3%83%88%e3%83%a1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ab%e3%82%88%e3%82%8b-autoscaling-%e3%82%b0%e3%83%ab%e3%83%bc%e3%83%97%e3%81%aeami%e6%9b%b4%e6%96%b0\/","title":{"rendered":"AWS Systems Manager \u30aa\u30fc\u30c8\u30e1\u30fc\u30b7\u30e7\u30f3\u306b\u3088\u308b AutoScaling \u30b0\u30eb\u30fc\u30d7\u306eAMI\u66f4\u65b0"},"content":{"rendered":"<p>EC2 AutoScaling\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u74b0\u5883\u3067\u306f\u3001OS\u5185\u306e\u66f4\u65b0\u306b\u4f34\u3044\u8d77\u52d5\u5143AMI\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304d\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306bAMI\u66f4\u65b0\u7528\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9(AutoScaling\u30b0\u30eb\u30fc\u30d7\u306b\u6240\u5c5e\u3057\u306a\u3044)\u3092\u7528\u610f\u3057\u3066\u304a\u304d\u3001<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h10_14.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17320\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h10_14.png\" alt=\"\" width=\"427\" height=\"299\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h10_14.png 427w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h10_14-300x210.png 300w\" sizes=\"auto, (max-width: 427px) 100vw, 427px\" \/><\/a>\n<ol>\n<li>AMI\u66f4\u65b0\u7528\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3067\u3001OS\u5185\u306e\u66f4\u65b0\u4f5c\u696d\u3092\u5b9f\u65bd<\/li>\n<li>AMI\u66f4\u65b0\u7528\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u5143\u306bAMI\u3092\u4f5c\u6210<\/li>\n<li>\u4f5c\u6210\u3057\u305fAMI\u3092\u5143\u306bAutoScaling\u8d77\u52d5\u8a2d\u5b9a\u3092\u4f5c\u6210<\/li>\n<li>\u5bfe\u8c61\u306eAutoScaling\u30b0\u30eb\u30fc\u30d7\u3092\u3001\u4f5c\u6210\u3057\u305f\u8d77\u52d5\u8a2d\u5b9a\u3092\u53c2\u7167\u3059\u308b\u3088\u3046\u66f4\u65b0<\/li>\n<\/ol>\n<p>\u3068\u3044\u3063\u305f\u6d41\u308c\u3067\u884c\u3044\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u3001SSM Automation \uff0b CloudWatch Events \u3092\u5229\u7528\u3057\u3001(2)\uff5e(4)\u3092\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u5b9f\u884c\u3055\u305b\u3066\u307f\u307e\u3059\u3002<\/p>\n<h3>\u8a2d\u5b9a\u65b9\u6cd5<\/h3>\n<h4>CloudFormation\u30b9\u30bf\u30c3\u30af\u4f5c\u6210<\/h4>\n<p>\u4ee5\u4e0b\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u5229\u7528\u3057CloudFormation\u30b9\u30bf\u30c3\u30af\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>AWSTemplateFormatVersion: \"2010-09-09\"\nDescription: \n  IAM Role and SSM Automation Document for Updating AutoScaling AMI.\n\n# ------------------------------------------------------------#\n# METADATA\n# ------------------------------------------------------------#\nMetadata: \n  \"AWS::CloudFormation::Interface\": \n    ParameterGroups: \n      - Label: \n          default: \"IAM Role: CloudWatch Events executes SSM Automation\"\n        Parameters: \n          - CloudWatchEventsRoleName\n          - CloudWatchEventsRolePolicyName\n      - Label: \n          default: \"IAM Role: SSM Automation updates AutoScalingGroup AMI\"\n        Parameters: \n          - SSMAutomationRoleName\n          - SSMAutomationRolePolicyName\n\n    ParameterLabels: \n      CloudWatchEventsRoleName: \n        default: \"IAM Role Name\"\n      CloudWatchEventsRolePolicyName: \n        default: \"IAM Policy Name\"\n      SSMAutomationRoleName: \n        default: \"IAM Role Name\"\n      SSMAutomationRolePolicyName: \n        default: \"IAM Policy Name\"\n\n# ------------------------------------------------------------#\n# PARAMETERS\n# ------------------------------------------------------------# \nParameters:\n  CloudWatchEventsRoleName:\n    Type: String\n    Default: \"EventsRoleForExecSSMAutomation\"\n\n  CloudWatchEventsRolePolicyName:\n    Type: String\n    Default: \"PolicyForExecSSMAutomation\"\n\n  SSMAutomationRoleName:\n    Type: String\n    Default: \"SSMRoleForUpdateAutoScalingGroupAMI\"\n\n  SSMAutomationRolePolicyName:\n    Type: String\n    Default: \"PolicyForUpdateAutoScalingGroupAMI\"\n\n# ------------------------------------------------------------#\n# RESOURCES\n# ------------------------------------------------------------#\nResources: \n# IAM Role: CloudWatch Events executes SSM Automation\n  CloudWatchEventsRole:\n    Type: AWS::IAM::Role\n    Properties:\n      RoleName: !Ref CloudWatchEventsRoleName\n      AssumeRolePolicyDocument:\n        Version: '2012-10-17'\n        Statement:\n        - Effect: Allow\n          Principal:\n            Service:\n            - events.amazonaws.com\n          Action:\n          - sts:AssumeRole\n      Policies: \n        - \n          PolicyName: !Ref CloudWatchEventsRolePolicyName\n          PolicyDocument: \n            Version: \"2012-10-17\"\n            Statement: \n              - \n                Effect: \"Allow\"\n                Action: \n                  - \"ssm:StartAutomationExecution\"\n                  - \"iam:PassRole\"\n                Resource: \"*\"\n\n# IAM Role: SSM Automation updates AutoScalingGroup AMI\n  SSMAutomationRole:\n    Type: AWS::IAM::Role\n    Properties:\n      RoleName: !Ref SSMAutomationRoleName\n      AssumeRolePolicyDocument:\n        Version: '2012-10-17'\n        Statement:\n        - Effect: Allow\n          Principal:\n            Service:\n            - ssm.amazonaws.com\n          Action:\n          - sts:AssumeRole\n      Policies: \n        - \n          PolicyName: !Ref SSMAutomationRolePolicyName\n          PolicyDocument: \n            Version: \"2012-10-17\"\n            Statement: \n              - \n                Effect: \"Allow\"\n                Action: \n                  - \"autoscaling:CreateLaunchConfiguration\"\n                  - \"autoscaling:UpdateAutoScalingGroup\"\n                  - \"ec2:CreateImage\"\n                  - \"ec2:DescribeImages\"\n                Resource: \"*\"\n\n# SSM Automation Document\n  AutomationDocument:\n    Type: \"AWS::SSM::Document\"\n    Properties:\n      DocumentType: Automation\n      Content:\n        description: Automation Document for Updating AMI for AutoScaling Group\n        schemaVersion: '0.3'\n        assumeRole: \"{{ AutomationAssumeRole }}\"\n        parameters:\n          AutomationAssumeRole:\n            type: String\n            description: \"(Optional) The ARN of the role that allows Automation to perform the actions on your behalf.\"\n            default: !GetAtt SSMAutomationRole.Arn\n          InstanceId:\n            type: String\n            description: \"(Required) Instance id of instance that ami is created from.\"\n          LaunchConfigPrefix:\n            type: String\n            description: \"(Required) Name Prefix of Launch Configuration to create.\"\n          AutoScalingGroupName:\n            type: String\n            description: \"(Required) Name of AutoScaling Group which already exists.\"\n        mainSteps:\n        - name: createImage\n          action: aws:createImage\n          inputs:\n            InstanceId: \"{{ InstanceId }}\"\n            ImageName: \"{{ InstanceId }}_{{ global:DATE }}\"\n            NoReboot: true\n            ImageDescription: \"{{ InstanceId }}_{{ global:DATE }}\"\n        - name: CreateLaunchConfiguration\n          action: aws:executeAwsApi\n          inputs:\n            Service: autoscaling\n            Api: CreateLaunchConfiguration\n            InstanceId: \"{{ InstanceId }}\"\n            ImageId: \"{{ createImage.ImageId }}\"\n            LaunchConfigurationName: \"{{ LaunchConfigPrefix }}_{{ global:DATE }}\"\n        - name: UpdateAutoScalingGroup\n          action: aws:executeAwsApi\n          inputs:\n            Service: autoscaling\n            Api: UpdateAutoScalingGroup\n            AutoScalingGroupName: \"{{ AutoScalingGroupName }}\"\n            LaunchConfigurationName: \"{{ LaunchConfigPrefix }}_{{ global:DATE }}\"\n\n# ------------------------------------------------------------#\n# OUTPUTS\n# ------------------------------------------------------------#\nOutputs:\n  AutomationDocument:\n    Description: Automation Document Name\n    Value: !Ref AutomationDocument\n<\/pre>\n<p>\u3053\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u3001\u4ee5\u4e0b\u30ea\u30bd\u30fc\u30b9\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<ul>\n<li>(2)\uff5e(4)\u3092\u884c\u3046\u70ba\u306eSSM Automation\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/li>\n<li>SSM Automation\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u5185\u5bb9(AutoScaling AMI\u66f4\u65b0)\u3092\u5b9f\u884c\u3059\u308b\u70ba\u306eIAM\u30ed\u30fc\u30eb<\/li>\n<li>CloudWatch Events \u304b\u3089 SSM Automation\u3092\u5b9f\u884c\u3059\u308b\u70ba\u306eIAM\u30ed\u30fc\u30eb<\/li>\n<\/ul>\n<h4>CloudWatch Events \u30eb\u30fc\u30eb\u306e\u4f5c\u6210<\/h4>\n<p>CloudWatch\u306e\u64cd\u4f5c\u753b\u9762\u3067\u3001\u30eb\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h23_22.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17322\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h23_22.png\" alt=\"\" width=\"826\" height=\"517\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h23_22.png 826w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h23_22-300x188.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h23_22-768x481.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h23_22-728x456.png 728w\" sizes=\"auto, (max-width: 826px) 100vw, 826px\" \/><\/a>\n<p>AutoScaling\u306e\u8d77\u52d5\u5143AMI\u66f4\u65b0\u3092\u5b9f\u65bd\u3059\u308b\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u5834\u5408\u3001\u65e5\u672c\u6642\u9593\u3067\u6bce\u65e514:30\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f[\u30bf\u30fc\u30b2\u30c3\u30c8\u306e\u8ffd\u52a0]\u3092\u9078\u629e\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h24_05.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-17323\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h24_05-1024x549.png\" alt=\"\" width=\"728\" height=\"390\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h24_05-1024x549.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h24_05-300x161.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h24_05-768x412.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h24_05-728x390.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h24_05.png 1199w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<p>\u4ee5\u4e0b\u306e\u901a\u308a\u30bf\u30fc\u30b2\u30c3\u30c8\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<table style=\"height: 250px;\" width=\"856\">\n<tbody>\n<tr>\n<td width=\"197\">\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/td>\n<td width=\"395\">[\u30b9\u30bf\u30c3\u30af\u540d]-AutomationDocument-[\u30e9\u30f3\u30c0\u30e0\u6587\u5b57\u5217]\n<p>(CFn\u306b\u3088\u308a\u4f5c\u6210\u3055\u308c\u305fSSM\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u540d)<\/td>\n<\/tr>\n<tr>\n<td>InstanceId<\/td>\n<td>AMI\u66f4\u65b0\u7528\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306eID<\/td>\n<\/tr>\n<tr>\n<td>AutoScalingGroupName<\/td>\n<td>\u5bfe\u8c61\u306eAutoScaling\u30b0\u30eb\u30fc\u30d7\u540d<\/td>\n<\/tr>\n<tr>\n<td>LaunchConfigPrefix<\/td>\n<td>\u65b0\u3057\u304f\u4f5c\u6210\u3055\u308c\u308b\u8d77\u52d5\u8a2d\u5b9a\u306e\u63a5\u982d\u8f9e(\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9)<\/td>\n<\/tr>\n<tr>\n<td>\u65e2\u5b58\u306e\u30ed\u30fc\u30eb\u3092\u4f7f\u7528<\/td>\n<td>EventsRoleForExecSSMAutomation (\u65e2\u5b9a\u306eIAM\u30ed\u30fc\u30eb\u540d)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_33.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17324\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_33.png\" alt=\"\" width=\"811\" height=\"890\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_33.png 811w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_33-273x300.png 273w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_33-768x843.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_33-728x799.png 728w\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" \/><\/a>\n<p>\u9069\u5f53\u306a\u540d\u524d\u3092\u8a2d\u5b9a\u3057\u3001\u30eb\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_57.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17327\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_57.png\" alt=\"\" width=\"868\" height=\"340\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_57.png 868w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_57-300x118.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_57-768x301.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_14h25_57-728x285.png 728w\" sizes=\"auto, (max-width: 868px) 100vw, 868px\" \/><\/a>\n<p>&nbsp;<\/p>\n<h4>\u7a3c\u50cd\u78ba\u8a8d<\/h4>\n<p>\u5b9f\u969b\u306b\u8d77\u52d5\u5143AMI\u304c\u66f4\u65b0\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n<strong>[\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9ID]_[YY-MM-DD]<\/strong> \u3068\u3044\u3046\u540d\u524d\u3067AMI\u304c\u4f5c\u6210\u3055\u308c\u3066\u3044\u3066\u3001<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h06_55.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17330\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h06_55.png\" alt=\"\" width=\"731\" height=\"169\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h06_55.png 731w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h06_55-300x69.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h06_55-728x169.png 728w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/a>\n<p>\u305d\u306eAMI\u3092\u6307\u5b9a\u3057\u305f\u8d77\u52d5\u8a2d\u5b9a\u304c <strong>[\u6307\u5b9a\u3057\u305f\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9]_[YY-MM-DD]<\/strong> \u3068\u3044\u3046\u540d\u524d\u3067\u4f5c\u6210\u3055\u308c\u3066\u3044\u3066\u3001<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h04_14.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-17329\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h04_14-1024x333.png\" alt=\"\" width=\"728\" height=\"237\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h04_14-1024x333.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h04_14-300x97.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h04_14-768x250.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h04_14-728x237.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h04_14.png 1031w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<p>\u5bfe\u8c61\u306eAutoScaling\u30b0\u30eb\u30fc\u30d7\u3067\u305d\u306e\u8d77\u52d5\u8a2d\u5b9a\u304c\u53c2\u7167\u3055\u308c\u3066\u3044\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h02_56.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17328\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h02_56.png\" alt=\"\" width=\"634\" height=\"502\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h02_56.png 634w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h02_56-300x238.png 300w\" sizes=\"auto, (max-width: 634px) 100vw, 634px\" \/><\/a>\n<p>\u66f4\u65b0\u51e6\u7406\u306e\u8a73\u7d30\u306fSystems Manager \u30aa\u30fc\u30c8\u30e1\u30fc\u30b7\u30e7\u30f3\u306e\u753b\u9762\u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<br \/>\n\u5b9f\u884cID\u3092\u9078\u629e\u3059\u308b\u3068\u3088\u308a\u8a73\u7d30\u306a\u5185\u5bb9\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_45-00.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-17332\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_45-00-1024x275.png\" alt=\"\" width=\"728\" height=\"196\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_45-00-1024x275.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_45-00-300x81.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_45-00-768x206.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_45-00-728x196.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_45-00.png 1444w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<p>\u30b9\u30c6\u30c3\u30d7\u3054\u3068(AMI\u4f5c\u6210\u3001\u8d77\u52d5\u8a2d\u5b9a\u4f5c\u6210\u3001AutoScaling\u30b0\u30eb\u30fc\u30d7\u66f4\u65b0)\u306e\u72b6\u6cc1\u3092\u78ba\u8a8d\u3057\u305f\u3044\u5834\u5408\u306f\u30b9\u30c6\u30c3\u30d7ID\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_58.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17333\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_58.png\" alt=\"\" width=\"984\" height=\"702\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_58.png 984w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_58-300x214.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_58-768x548.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h08_58-728x519.png 728w\" sizes=\"auto, (max-width: 984px) 100vw, 984px\" \/><\/a>\n<p>\u30b9\u30c6\u30c3\u30d7(AMI\u4f5c\u6210)\u306e\u8a73\u7d30\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h09_06.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-17334\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h09_06-1024x580.png\" alt=\"\" width=\"728\" height=\"412\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h09_06-1024x580.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h09_06-300x170.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h09_06-768x435.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h09_06-240x135.png 240w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h09_06-728x412.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/10\/2019-10-16_15h09_06.png 1115w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<h3>\u8a2d\u5b9a\u5185\u5bb9(CloudFormation\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u5bb9\u89e3\u8aac)<\/h3>\n<h4>SSM Automation\u3092\u5b9f\u884c\u3059\u308b\u70ba\u306eCloudWatch Events\u7528IAM\u30ed\u30fc\u30eb<\/h4>\n<p>CloudWatch Events(events.amazonaws.com)\u304b\u3089\u3001SSM Automation\u304c\u5b9f\u884c\u53ef\u80fd\u306a\u30ed\u30fc\u30eb\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>...\n# IAM Role: CloudWatch Events executes SSM Automation\n  CloudWatchEventsRole:\n    Type: AWS::IAM::Role\n    Properties:\n      RoleName: !Ref CloudWatchEventsRoleName\n      AssumeRolePolicyDocument:\n        Version: '2012-10-17'\n        Statement:\n        - Effect: Allow\n          Principal:\n            Service:\n            - <span style=\"color: #ffff00;\">events.amazonaws.com<\/span>\n          Action:\n          - sts:AssumeRole\n      Policies: \n        - \n          PolicyName: !Ref CloudWatchEventsRolePolicyName\n          PolicyDocument: \n            Version: \"2012-10-17\"\n            Statement: \n              - \n                Effect: \"Allow\"\n                Action: \n                  - \"<span style=\"color: #ffff00;\">ssm:StartAutomationExecution<\/span>\"\n                  - \"<span style=\"color: #ffff00;\">iam:PassRole<\/span>\"\n                Resource: \"*\"\n...\n<\/pre>\n<h4>AutoScaling\u30b0\u30eb\u30fc\u30d7\u3092\u66f4\u65b0\u3059\u308b\u70ba\u306eSSM\u7528IAM\u30ed\u30fc\u30eb<\/h4>\n<p>Systems Manager(ssm.amazonaws.com)\u304b\u3089\u3001AMI\u4f5c\u6210\u30fb\u8d77\u52d5\u8a2d\u5b9a\u4f5c\u6210\u30fbAutoScaling\u30b0\u30eb\u30fc\u30d7\u66f4\u65b0\u304c\u5b9f\u884c\u53ef\u80fd\u306a\u30ed\u30fc\u30eb\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>...\n# IAM Role: SSM Automation updates AutoScalingGroup AMI\n  SSMAutomationRole:\n    Type: AWS::IAM::Role\n    Properties:\n      RoleName: !Ref SSMAutomationRoleName\n      AssumeRolePolicyDocument:\n        Version: '2012-10-17'\n        Statement:\n        - Effect: Allow\n          Principal:\n            Service:\n            - <span style=\"color: #ffff00;\">ssm.amazonaws.com<\/span>\n          Action:\n          - sts:AssumeRole\n      Policies: \n        - \n          PolicyName: !Ref SSMAutomationRolePolicyName\n          PolicyDocument: \n            Version: \"2012-10-17\"\n            Statement: \n              - \n                Effect: \"Allow\"\n                Action: \n                  - \"<span style=\"color: #ffff00;\">autoscaling:CreateLaunchConfiguration<\/span>\"\n                  - \"<span style=\"color: #ffff00;\">autoscaling:UpdateAutoScalingGroup<\/span>\"\n                  - \"<span style=\"color: #ffff00;\">ec2:CreateImage<\/span>\"\n                  - \"<span style=\"color: #ffff00;\">ec2:DescribeImages<\/span>\"\n                Resource: \"*\"\n...\n<\/pre>\n<h4>SSM Automation\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/h4>\n<p>CloudFormation\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3082SSM\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3082YAML\u306a\u306e\u3067\u5206\u304b\u308a\u306b\u304f\u3044\u3067\u3059\u304c\u3001<br \/>\nContent\u4ee5\u4e0b\u304cSSM\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u5185\u5bb9\u3067\u3059\u3002<\/p>\n<pre>...\n# SSM Automation Document\n  AutomationDocument:\n    Type: \"AWS::SSM::Document\"\n    Properties:\n      DocumentType: Automation\n      <span style=\"color: #ffff00;\">Content<\/span>:\n        description: Automation Document for Updating AMI for AutoScaling Group\n        schemaVersion: '0.3'\n        assumeRole: \"{{ AutomationAssumeRole }}\"\n        parameters:\n          AutomationAssumeRole:\n            type: String\n            description: \"(Optional) The ARN of the role that allows Automation to perform the actions on your behalf.\"\n            default: !GetAtt SSMAutomationRole.Arn\n          InstanceId:\n            type: String\n            description: \"(Required) Instance id of instance that ami is created from.\"\n          LaunchConfigPrefix:\n            type: String\n            description: \"(Required) Name Prefix of Launch Configuration to create.\"\n          AutoScalingGroupName:\n            type: String\n            description: \"(Required) Name of AutoScaling Group which already exists.\"\n        mainSteps:\n        - name: <span style=\"color: #ffff00;\">createImage<\/span>\n          action: aws:createImage\n          inputs:\n            InstanceId: \"{{ InstanceId }}\"\n            ImageName: \"{{ InstanceId }}_{{ global:DATE }}\"\n            NoReboot: true\n            ImageDescription: \"{{ InstanceId }}_{{ global:DATE }}\"\n        - name: <span style=\"color: #ffff00;\">CreateLaunchConfiguration<\/span>\n          action: aws:executeAwsApi\n          inputs:\n            Service: autoscaling\n            Api: CreateLaunchConfiguration\n            <span style=\"color: #ff0000;\">InstanceId<\/span>: \"{{ InstanceId }}\"\n            ImageId: \"{{ createImage.ImageId }}\"\n            LaunchConfigurationName: \"{{ LaunchConfigPrefix }}_{{ global:DATE }}\"\n        - name: <span style=\"color: #ffff00;\">UpdateAutoScalingGroup<\/span>\n          action: aws:executeAwsApi\n          inputs:\n            Service: autoscaling\n            Api: UpdateAutoScalingGroup\n            AutoScalingGroupName: \"{{ AutoScalingGroupName }}\"\n            LaunchConfigurationName: \"{{ LaunchConfigPrefix }}_{{ global:DATE }}\"\n...\n<\/pre>\n<ul>\n<li>createImage\u30b9\u30c6\u30c3\u30d7\u3067(\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u518d\u8d77\u52d5\u7121\u3057\u3067) <strong>[\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9ID]_[YY-MM-DD]<\/strong> \u3068\u3044\u3046AMI\u3092\u4f5c\u6210\u3057\u3001<\/li>\n<li>CreateLaunchConfiguration\u30b9\u30c6\u30c3\u30d7\u3067\u305d\u306eAMI\u3092\u5143\u306b <strong>[\u6307\u5b9a\u3057\u305f\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9]_[YY-MM-DD]<\/strong> \u3068\u3044\u3046\u8d77\u52d5\u8a2d\u5b9a\u3092\u4f5c\u6210\u3057\u3001<\/li>\n<li>UpdateAutoScalingGroup\u30b9\u30c6\u30c3\u30d7\u3067\u3001\u305d\u306e\u8d77\u52d5\u8a2d\u5b9a\u3092\u53c2\u7167\u3059\u308b\u3088\u3046\u5bfe\u8c61\u306eAutoScaling\u30b0\u30eb\u30fc\u30d7\u3092\u66f4\u65b0\u3057\u3066\u3044\u307e\u3059\u3002<\/li>\n<\/ul>\n<p>\u307e\u305f\u3001CreateLaunchConfiguration\u30b9\u30c6\u30c3\u30d7\u3067\u306f<span style=\"color: #ff0000;\">InstanceId<\/span>\u3068\u3044\u3046\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u308c\u306f\u6307\u5b9a\u3057\u305f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5f15\u304d\u7d99\u3044\u3060\u8d77\u52d5\u8a2d\u5b9a\u3092\u4f5c\u6210\u3057\u3066\u304f\u308c\u308b\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/docs.aws.amazon.com\/ja_jp\/autoscaling\/ec2\/userguide\/create-lc-with-instanceID.html\" target=\"_blank\" rel=\"noopener\">EC2 \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f7f\u7528\u3057\u305f\u8d77\u52d5\u8a2d\u5b9a\u306e\u4f5c\u6210<\/a><\/p>\n<p>\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>EC2 AutoScaling\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u74b0\u5883\u3067\u306f\u3001OS\u5185\u306e\u66f4\u65b0\u306b\u4f34\u3044\u8d77\u52d5\u5143AMI\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304d\u307e\u3059\u3002 \u4f8b\u3048\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306bAMI\u66f4\u65b0\u7528\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9(AutoScaling\u30b0\u30eb\u30fc\u30d7\u306b\u6240\u5c5e\u3057\u306a\u3044)\u3092\u7528\u610f&#8230;<\/p>\n","protected":false},"author":60,"featured_media":17248,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"17319","footnotes":""},"categories":[20],"tags":[],"class_list":{"0":"post-17319","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-aws","8":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/17319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/60"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=17319"}],"version-history":[{"count":13,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/17319\/revisions"}],"predecessor-version":[{"id":17391,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/17319\/revisions\/17391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/17248"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=17319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=17319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=17319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}