{"id":29199,"date":"2025-09-02T17:16:05","date_gmt":"2025-09-02T08:16:05","guid":{"rendered":"https:\/\/www.skyarch.net\/blog\/?p=29199"},"modified":"2025-09-02T17:16:12","modified_gmt":"2025-09-02T08:16:12","slug":"ssm-change-calendar%e3%81%a7%e5%ae%9a%e6%99%82%e9%80%80%e7%a4%be%e3%82%92%e4%bf%83%e9%80%b2%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/ssm-change-calendar%e3%81%a7%e5%ae%9a%e6%99%82%e9%80%80%e7%a4%be%e3%82%92%e4%bf%83%e9%80%b2%e3%81%99%e3%82%8b\/","title":{"rendered":"SSM change calendar\u3067\u5b9a\u6642\u9000\u793e\u3092\u4fc3\u9032\u3059\u308b"},"content":{"rendered":"<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p><code>SSM change calendar<\/code>\u3092\u7d39\u4ecb\u3059\u308b\u3064\u3044\u3067\u306b\u3001\u5b9a\u6642\u3092\u904e\u304e\u305f\u3089\u4f5c\u696d\u30e6\u30fc\u30b6\u30fc\u306eIAM\u30ed\u30fc\u30eb\u3092<code>ReadOnly<\/code>\u306b\u66f4\u65b0\u3057\u3001\u7269\u7406\u7684\u306b\u4ed5\u4e8b\u3092\u3067\u304d\u306a\u304f\u3059\u308b\u3053\u3068\u3067\u5b9a\u6642\u9000\u793e\u3092\u4fc3\u9032\u3059\u308b\u4ed5\u7d44\u307f\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/eaea6cc56280fc8b59a73872c4742300.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/eaea6cc56280fc8b59a73872c4742300.png\" alt=\"\" \/><\/a>\n<h2>SSM change calendar \u3068\u306f\uff1f<\/h2>\n<p>\u904b\u7528\u30eb\u30fc\u30eb\u3092\u30ab\u30ec\u30f3\u30c0\u30fc\u4e0a\u3067\u6307\u5b9a\u3057\u3066\u3001SSM\u3084\u305d\u306e\u4ed6\u30b5\u30fc\u30d3\u30b9\u3068\u9023\u643a\u3067\u304d\u308b\u30b5\u30fc\u30d3\u30b9\u3067\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u300c\u6bce\u6708\u7b2c\u4e09\u55b6\u696d\u65e5\u306bSNS\u3067\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u300d\u300c\u6bce\u9031\u91d1\u66dc\u65e5\u306b\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u306e\u305f\u3081\u306e\u30d0\u30c3\u30c1\u3092\u5b9f\u884c\u3059\u308b\u300d\u3068\u3044\u3063\u305f\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u304c\u8a2d\u5b9a\u3067\u304d\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u4e0a\u304b\u3089\u30ab\u30ec\u30f3\u30c0\u30fc\u3067\u308f\u304b\u308a\u3084\u3059\u304f\u78ba\u8a8d\u304c\u884c\u3048\u307e\u3059\u3002<\/p>\n<p><code>EventBridge<\/code>\u3067\u3082\u4e00\u65e5\u4e00\u56de\u6c7a\u3081\u3089\u308c\u305f\u6642\u9593\u306b\u5b9f\u884c\u3001\u3068\u3044\u3046\u3088\u3046\u306a\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u306f\u884c\u3048\u307e\u3059\u304c\u3001\u66dc\u65e5\u306e\u6307\u5b9a\u3084\u3001\u9006\u306b\u300c\u4f5c\u696d\u3092\u3057\u3066\u306f\u3044\u3051\u306a\u3044\u6642\u9593\u300d\u3092\u5b9a\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u306f<code>SSM change calendar<\/code>\u306a\u3089\u3067\u306f\u306e\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<p>\u3088\u308a\u8a73\u3057\u3044\u8aac\u660e\u306f\u4e0b\u8a18\u516c\u5f0f\u30b5\u30a4\u30c8\u3092\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<br \/>\n<a href=\"https:\/\/docs.aws.amazon.com\/ja_jp\/systems-manager\/latest\/userguide\/systems-manager-change-calendar.html\">https:\/\/docs.aws.amazon.com\/ja_jp\/systems-manager\/latest\/userguide\/systems-manager-change-calendar.html<\/a><\/p>\n<h2>\u4f5c\u6210\u624b\u9806<\/h2>\n<p>\u7c21\u5358\u306a\u7d39\u4ecb\u3082\u7d42\u308f\u3063\u305f\u306e\u3067\u3001\u3053\u3053\u304b\u3089\u306f\u6c7a\u3081\u3089\u308c\u305f\u6642\u523b\u306b\u4f5c\u696d\u30e6\u30fc\u30b6\u30fc\u306eIAM\u30ed\u30fc\u30eb\u3092<code>ReadOnly<\/code>\u306b\u66f4\u65b0\u3057\u3001\u7269\u7406\u7684\u306b\u4ed5\u4e8b\u3092\u3067\u304d\u306a\u304f\u3059\u308b\u4ed5\u7d44\u307f\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30ab\u30ec\u30f3\u30c0\u30fc\u4f5c\u6210<\/h3>\n<p><code>AWS Systems Manager<\/code>\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u3078\u30a2\u30af\u30bb\u30b9\u3057<code>[\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u5909\u66f4]\u2192[\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u4f5c\u6210]<\/code>\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-27_17h25_40.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-27_17h25_40-1024x454.png\" alt=\"\" \/><\/a>\n<p>\u4e0b\u8a18\u306e\u8a2d\u5b9a\u3067\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u540d\u524d\u7b49\u306f\u4efb\u610f\u3067\u3059\u304c\u3001\u30ab\u30ec\u30f3\u30c0\u30fc\u30bf\u30a4\u30d7\u306f\u300c\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u9589\u3058\u308b\u300d\u3092\u8a2d\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/1dab45ba42e17a49e97b8c48a5dfa8c6.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/1dab45ba42e17a49e97b8c48a5dfa8c6-1024x515.png\" alt=\"\" \/><\/a>\n<p>\u30ab\u30ec\u30f3\u30c0\u30fc\u304c\u7121\u4e8b\u4f5c\u6210\u3067\u304d\u305f\u3089<code>[\u30a4\u30d9\u30f3\u30c8\u3092\u4f5c\u6210]<\/code>\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-27_17h46_20.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-27_17h46_20-1024x418.png\" alt=\"\" \/><\/a>\n<p>\u4e0b\u8a18\u306e\u8a2d\u5b9a\u3067\u30a4\u30d9\u30f3\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u30c6\u30b9\u30c8\u306a\u306e\u3067\u624b\u52d5\u3067\u65e5\u4ed8\u3092\u5165\u529b\u3092\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u5b9f\u969b\u306b\u69cb\u7bc9\u3092\u3059\u308b\u969b\u306f\u30ab\u30ec\u30f3\u30c0\u30fc\u4f5c\u6210\u6642\u306b\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u30d5\u30a1\u30a4\u30eb\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u307b\u3046\u304c\u65e9\u3044\u306e\u3067\u304a\u8a66\u3057\u304f\u3060\u3055\u3044\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-27_17h49_06.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-27_17h49_06-1024x496.png\" alt=\"\" \/><\/a>\n<p>\u3053\u308c\u3067\u3001\u6bce\u65e5<code>9:00-18:00<\/code>\u306e\u307f\u30b9\u30c6\u30fc\u30bf\u30b9\u304c<code>OPEN<\/code>\u306b\u306a\u308b\u30ab\u30ec\u30f3\u30c0\u30fc\u304c\u5b8c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n<h3>EventBridge \u4f5c\u6210<\/h3>\n<p>\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u72b6\u614b\u306b\u5408\u308f\u305b\u305f\u30eb\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n<code>EventBridge<\/code>\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089<code>[\u30eb\u30fc\u30eb]\u2192[\u30eb\u30fc\u30eb\u306e\u4f5c\u6210]<\/code>\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-29_15h18_31.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-29_15h18_31-1024x444.png\" alt=\"\" \/><\/a>\n<p>\u4e0b\u8a18\u306e\u30a4\u30d9\u30f3\u30c8\u30d1\u30bf\u30fc\u30f3\u3067\u30eb\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><code>{\n  \"source\": [\"aws.ssm\"],\n  \"detail-type\": [\"Calendar State Change\"],\n  \"resources\": [\"\u4f5c\u6210\u3057\u305f\u30ab\u30ec\u30f3\u30c0\u30fc\u306earn\"],\n  \"detail\": {\n    \"state\": [\"OPEN\", \"CLOSED\"]\n  }\n}<\/code><\/pre>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-09-01_15h58_05.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-09-01_15h58_05-1024x719.png\" alt=\"\" \/><\/a>\n<p>\u30bf\u30fc\u30b2\u30c3\u30c8\u306f\u5f8c\u7a0b\u4f5c\u6210\u3059\u308bLambda\u3092\u8a2d\u5b9a\u3059\u308b\u306e\u3067\u3001\u3053\u306e\u6642\u70b9\u3067\u306f\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<h3>Lambda \u4f5c\u6210<\/h3>\n<p>Lamnda\u95a2\u6570\u3092\u4f5c\u6210\u3057\u3001\u30c8\u30ea\u30ac\u30fc\u3068\u3057\u3066\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f<code>EventBridge<\/code>\u306e\u30eb\u30fc\u30eb\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-29_15h24_31.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/2025-08-29_15h24_31-1024x404.png\" alt=\"\" \/><\/a>\n<p>\u95a2\u6570\u306e\u5185\u5bb9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"lang:python decode:true\" title=\"function\">import boto3\n\niam = boto3.client(\"iam\") \nadmin_arn = \"arn:aws:iam::aws:policy\/AdministratorAccess\" \nreadonly_arn = \"arn:aws:iam::aws:policy\/ReadOnlyAccess\" \ndevelop_user = \"\u5bfe\u8c61\u30e6\u30fc\u30b6\u30fc\u540d\" \n\ndef lambda_handler(event, context): \n    state = event.get(\"detail\", {}).get(\"state\", []) \n\n    if state == \"OPEN\": \n       change_policy(develop_user, admin_arn) \n       print(\"\u59cb\u696d\u6642\u9593\u306a\u306e\u3067Admin\u6a29\u9650\u3092\u4ed8\u4e0e\u3057\u307e\u3057\u305f\u3002\u4eca\u65e5\u3082\u4e00\u65e5\u9811\u5f35\u308d\u3046\uff01\") \n       return {\"statusCode\": 200, \"body\": \"OK\"} \n    elif state == \"CLOSED\": \n       change_policy(develop_user, readonly_arn)\n       print(\"\u5b9a\u6642\u306a\u306e\u3067ReadOnly\u6a29\u9650\u3092\u4ed8\u4e0e\u3057\u307e\u3057\u305f\u3002\u65e9\u304f\u5e30\u308d\u3046\uff01\") \n       return {\"statusCode\": 200, \"body\": \"OK\"} \n    else: \n       print(f\"Unknown state: {state}\") \n       return {\"statusCode\": 400, \"body\": \"NG\"} \n\ndef change_policy(user_name, target_policy_arn): \n    attached = iam.list_attached_user_policies(UserName=user_name) \n    for policy in attached.get(\"AttachedPolicies\", []): \n        iam.detach_user_policy(UserName=user_name, PolicyArn=policy[\"PolicyArn\"]) \n\n    iam.attach_user_policy(UserName=user_name, PolicyArn=target_policy_arn)\n<\/pre>\n<p>\u4f5c\u6210\u5f8c\u3001\u5148\u307b\u3069\u306e<code>EventBridge<\/code>\u306e\u30eb\u30fc\u30eb\u306e\u30bf\u30fc\u30b2\u30c3\u30c8\u306b\u3053\u306e<code>Lambda<\/code>\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u95a2\u6570\u306e\u5b9f\u884c\u30ed\u30fc\u30eb\u306b\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u6a29\u9650\u306b\u52a0\u3048\u30e6\u30fc\u30b6\u30fc\u306e<code>IAM<\/code>\u3092\u5909\u66f4\u3067\u304d\u308b\u30dd\u30ea\u30b7\u30fc\u3068<code>EventBridge<\/code>\u95a2\u9023\u306e\u30dd\u30ea\u30b7\u30fc\u3092\u4ed8\u4e0e\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u52d5\u4f5c\u78ba\u8a8d<\/h3>\n<p>\u6642\u9593\u306b\u306a\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a4\u30d9\u30f3\u30c8\u304c<code>Lambda<\/code>\u3042\u3066\u306b\u9001\u4fe1\u3055\u308c\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u30ed\u30fc\u30eb\u304c\u66f4\u65b0\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\" title=\"event\">{ \n    'version': '0',\n    'id': '\u30a4\u30d9\u30f3\u30c8ID',\n    'detail-type': 'Calendar State Change', \n    'source': 'aws.ssm', \n    'account': 'xxxxxxxxxxxx', \n    'time': '2025-09-01T04:00:00Z', \n    'region': 'ap-northeast-1', \n    'resources': [ '\u30ab\u30ec\u30f3\u30c0\u30fc\u306eARN' ], \n    'detail': { \n                'state': 'OPEN', \n                'atTime': '2025-09-01T04:00:00Z', \n                'nextTransitionTime': '2025-09-01T04:30:00Z', \n                'event': 'test' \n              }\n}<code class=\"language-json\">\n<\/code><\/pre>\n<p>\u304d\u3061\u3093\u3068\u52d5\u4f5c\u3057\u305f\u304b\u306f<code>Lambda<\/code>\u306e\u30ed\u30b0\u304b\u3089\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/952805610560dd1a4a26554867501940.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/08\/952805610560dd1a4a26554867501940.png\" alt=\"\" \/><\/a>\n<h2>\u304a\u308f\u308a\u306b<\/h2>\n<p><code>SSM change calendar<\/code>\u306f\u3068\u3066\u3082\u4fbf\u5229\u306a\u6a5f\u80fd\u3067\u3059\u304c\u3001\u3042\u307e\u308a\u77e5\u540d\u5ea6\u304c\u306a\u3044\u3088\u3046\u306b\u611f\u3058\u305f\u306e\u3067\u4eca\u56de\u8a18\u4e8b\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u4f7f\u3044\u65b9\u6b21\u7b2c\u3067\u306f\u30eb\u30fc\u30c1\u30f3\u30ef\u30fc\u30af\u3092\u6e1b\u3089\u305b\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u306e\u3067\u3001\u8981\u4ef6\u306b\u5408\u308f\u305b\u3066\u305c\u3072\u3054\u6d3b\u7528\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b SSM change calendar\u3092\u7d39\u4ecb\u3059\u308b\u3064\u3044\u3067\u306b\u3001\u5b9a\u6642\u3092\u904e\u304e\u305f\u3089\u4f5c\u696d\u30e6\u30fc\u30b6\u30fc\u306eIAM\u30ed\u30fc\u30eb\u3092ReadOnly\u306b\u66f4\u65b0\u3057\u3001\u7269\u7406\u7684\u306b\u4ed5\u4e8b\u3092\u3067\u304d\u306a\u304f\u3059\u308b\u3053\u3068\u3067\u5b9a\u6642\u9000\u793e\u3092\u4fc3\u9032\u3059\u308b\u4ed5\u7d44\u307f\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002 SSM&#8230;<\/p>\n","protected":false},"author":219,"featured_media":29247,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/www.skyarch.net\/blog\/?p=29199","footnotes":""},"categories":[20,830],"tags":[],"class_list":{"0":"post-29199","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-aws","8":"category-systems-manager","9":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/29199","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\/219"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=29199"}],"version-history":[{"count":35,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/29199\/revisions"}],"predecessor-version":[{"id":29736,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/29199\/revisions\/29736"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/29247"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=29199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=29199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=29199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}