{"id":21169,"date":"2021-11-24T17:42:32","date_gmt":"2021-11-24T08:42:32","guid":{"rendered":"https:\/\/www.skyarch.net\/blog\/?p=21169"},"modified":"2021-11-24T17:42:33","modified_gmt":"2021-11-24T08:42:33","slug":"cfn-response-%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%82%92%e3%81%95%e3%82%89%e3%81%ab%e6%b4%bb%e7%94%a8%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/cfn-response-%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%82%92%e3%81%95%e3%82%89%e3%81%ab%e6%b4%bb%e7%94%a8%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b\/","title":{"rendered":"cfn-response \u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u3055\u3089\u306b\u6d3b\u7528\u3057\u3066\u307f\u308b"},"content":{"rendered":"<h1>\u6982\u8981<\/h1>\n<p>CloudFormation \u3067 Lambda-backed \u30ab\u30b9\u30bf\u30e0\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3059\u308b\u969b\u306b\u5229\u7528\u3059\u308b cfn-response \u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u3059\u304c\u3001\u5b9f\u4f53\u306f\u4ee5\u4e0b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/docs.aws.amazon.com\/ja_jp\/AWSCloudFormation\/latest\/UserGuide\/cfn-lambda-function-code-cfnresponsemodule.html#w2aac27c23c14b9c15\" target=\"_blank\" rel=\"noopener\">cfn-response \u30e2\u30b8\u30e5\u30fc\u30eb - \u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/a><\/p>\n<p>send \u30e1\u30bd\u30c3\u30c9\u306b\u6e21\u3059\u5f15\u6570\u306e\u3046\u3061\u5fc5\u9808\u306a\u306e\u306f event, context, responseStatus, responseData \u306e4\u3064\u306a\u306e\u3067\u3001\u3053\u306e4\u3064\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304c\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001<\/p>\n<pre>def send(event, context, responseStatus, responseData, <span style=\"color: #ffff00;\">physicalResourceId<\/span>=None, noEcho=False, <span style=\"color: #ffff00;\">reason<\/span>=None):\n    responseUrl = event['ResponseURL']\n<\/pre>\n<p>\u79c1\u304c\u6700\u8fd1\u91cd\u5b9d\u3057\u3066\u3044\u308b\u306e\u306f\u3001\u30aa\u30d7\u30b7\u30e7\u30f3\u5f15\u6570\u306e physicalResourceId \u3068 reason \u3067\u3059\u3002<br \/>\n\u672c\u8a18\u4e8b\u3067\u306f\u4e3b\u306b\u3053\u3061\u3089\u306e2\u3064\u306b\u3064\u3044\u3066\u304a\u8a71\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1>physicalResourceId<\/h1>\n<p>CloudFormation \u30b3\u30f3\u30bd\u30fc\u30eb\u4e0a\u3067\u306f\u300c\u7269\u7406 ID\u300d\u3068\u8868\u793a\u3055\u308c\u308b\u9805\u76ee\u3067\u3059\u3002<br \/>\n\u7279\u306b\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b CloudWatch Logs \u306e\u30ed\u30b0\u30b9\u30c8\u30ea\u30fc\u30e0\u540d\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h25_51.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-21173\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h25_51-1024x490.png\" alt=\"\" width=\"728\" height=\"348\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h25_51-1024x490.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h25_51-300x144.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h25_51-768x368.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h25_51-728x349.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h25_51.png 1136w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a><\/p>\n<h1>reason<\/h1>\n<p>\u3053\u3061\u3089\u306f\u300c\u72b6\u6cc1\u306e\u7406\u7531\u300d\u6b04\u306b\u8868\u793a\u3055\u308c\u308b\u30e1\u30c3\u30bb\u30fc\u30b8\u3067\u3059\u3002<br \/>\n\u7279\u306b\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9a\u578b\u7684\u306a\u30e1\u30c3\u30bb\u30fc\u30b8 + \u30ed\u30b0\u30b9\u30c8\u30ea\u30fc\u30e0\u540d\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h31_53.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-21174\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h31_53-1024x304.png\" alt=\"\" width=\"728\" height=\"216\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h31_53-1024x304.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h31_53-300x89.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h31_53-768x228.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h31_53-728x216.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h31_53.png 1375w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a><\/p>\n<h1>\u6d3b\u7528\u4f8b<\/h1>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u3053\u3061\u3089\u306f\u4ee5\u524d\u6295\u7a3f\u3057\u305f <a title=\"SSM Session Manager\u306e\u8a2d\u5b9a(\u30ed\u30ae\u30f3\u30b0\u306a\u3069)\u3092CloudFormation\u3067\u884c\u3046\" href=\"https:\/\/www.skyarch.net\/blog\/?p=19837\" target=\"_blank\" rel=\"noopener\">Session Manager \u306e\u8a2d\u5b9a\u3092\u884c\u3046\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8<\/a>\u306b\u5c11\u3057\u624b\u3092\u52a0\u3048\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<pre>AWSTemplateFormatVersion: \"2010-09-09\"\n\nParameters:\n  IdleSessionTimeout:\n    Type: Number\n    Default: 30\n\nResources:\n  SsmDocument:\n    Type: Custom::SsmDocument\n    Properties:\n      ServiceToken: !GetAtt Function.Arn\n      DocumentParams:\n        Name: SSM-SessionManagerRunShell\n        DocumentType: Session\n        DocumentFormat: JSON\n        Content: !Sub |\n          {\n            \"schemaVersion\": \"1.0\",\n            \"inputs\": {\n              \"cloudWatchEncryptionEnabled\": false,\n              \"s3BucketName\": \"\",\n              \"s3KeyPrefix\": \"\",\n              \"s3EncryptionEnabled\": false,\n              \"runAsDefaultUser\": \"\",\n              \"cloudWatchStreamingEnabled\": false,\n              \"kmsKeyId\": \"\",\n              \"runAsEnabled\": false,\n              \"idleSessionTimeout\": \"${IdleSessionTimeout}\",\n              \"shellProfile\": {\n                \"linux\": \"\",\n                \"windows\": \"\"\n              },\n              \"cloudWatchLogGroupName\": \"\"\n            },\n            \"description\": \"Document to hold regional settings for Session Manager\",\n            \"sessionType\": \"Standard_Stream\"\n          }\n\n  Function:\n    Type: AWS::Lambda::Function\n    DependsOn: FunctionLog\n    Properties:\n      FunctionName: !Join\n        - ''\n        - - ssm-document-custom-function-\n          - !Select [ '0', !Split [ '-', !Select [ '2', !Split [ '\/', !Ref AWS::StackId ] ] ] ]\n      Code:\n        ZipFile: |\n          import logging\n          import os\n          import traceback\n\n          import boto3\n          import cfnresponse\n          from botocore.exceptions import ClientError\n\n          logger = logging.getLogger()\n          logger.setLevel(os.environ['LOG_LEVEL'])\n\n          ssm = boto3.client('ssm')\n\n          def lambda_handler(event, context):\n              try:\n                  document_params = event['ResourceProperties']['DocumentParams']\n                  account_id = event['StackId'].split(':')[4]\n                  document_arn = f'arn:aws:ssm:{os.environ[\"AWS_REGION\"]}:{account_id}:document\/{document_params[\"Name\"]}'\n\n                  if event['RequestType'] in ['Create', 'Update']:\n                      if document_exists(document_params):\n                          update_document(document_params)\n                      else:\n                          create_document(document_params)\n\n                  cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, physicalResourceId=document_arn)\n              except:\n                  tb = traceback.format_exc()\n                  logger.error(tb)\n                  cfnresponse.send(event, context, cfnresponse.FAILED, {}, physicalResourceId=None, noEcho=False, reason=tb.replace('\\n', r'\\n'))\n\n          def document_exists(document_params:dict) -&gt; bool:\n              document_identifiers = ssm.list_documents(\n                  Filters=[\n                      {\n                          'Key': 'Name',\n                          'Values': [ document_params['Name'] ]\n                      },\n                      {\n                          'Key': 'Owner',\n                          'Values': [ 'Self' ]\n                      },\n                      {\n                          'Key': 'DocumentType',\n                          'Values': [ document_params['DocumentType'] ]\n                      },\n                  ],\n              )['DocumentIdentifiers']\n\n              if len(document_identifiers) == 0:\n                  return False\n              elif len(document_identifiers) == 1:\n                  return True\n\n          def create_document(document_params:dict) -&gt; None:\n              response = ssm.create_document(\n                  Content=document_params['Content'],\n                  Name=document_params['Name'],\n                  DocumentType=document_params['DocumentType'],\n                  DocumentFormat=document_params['DocumentFormat'],\n              )\n              logger.info(response)\n\n          def update_document(document_params:dict) -&gt; None:\n              try:\n                  updated_version = ssm.update_document(\n                      Content=document_params['Content'],\n                      Name=document_params['Name'],\n                      DocumentFormat=document_params['DocumentFormat'],\n                      DocumentVersion='$LATEST',\n                  )['DocumentDescription']['DocumentVersion']\n              except ClientError as e:\n                  if e.response['Error']['Code'] == 'DuplicateDocumentContent':\n                      logger.info('no update to the SSM document')\n                      return None\n                  else:\n                      raise e\n              response = ssm.update_document_default_version(\n                  Name=document_params['Name'],\n                  DocumentVersion=updated_version\n              )\n              logger.info(response)\n      Environment:\n        Variables:\n          LOG_LEVEL: INFO\n      Handler: index.lambda_handler\n      MemorySize: 128\n      Role: !GetAtt FunctionRole.Arn\n      Runtime: python3.8\n      Timeout: 120\n\n  FunctionRole:\n    Type: AWS::IAM::Role\n    Properties:\n      RoleName: !Join\n        - ''\n        - - ssm-document-custom-function-role-\n          - !Select [ '0', !Split [ '-', !Select [ '2', !Split [ '\/', !Ref AWS::StackId ] ] ] ]\n      AssumeRolePolicyDocument:\n        Version: '2012-10-17'\n        Statement:\n        - Effect: Allow\n          Principal:\n            Service:\n            - lambda.amazonaws.com\n          Action:\n          - sts:AssumeRole\n      Policies:\n        - PolicyName: ssm-document-policy\n          PolicyDocument:\n            Version: 2012-10-17\n            Statement:\n              - Effect: Allow\n                Action:\n                  - ssm:ListDocuments\n                Resource: \"*\"\n              - Effect: Allow\n                Action:\n                  - ssm:UpdateDocument\n                  - ssm:CreateDocument\n                  - ssm:UpdateDocumentDefaultVersion\n                Resource: !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:document\/SSM-SessionManagerRunShell\n        - PolicyName: lambda-logs-policy\n          PolicyDocument:\n            Version: 2012-10-17\n            Statement:\n              - Effect: Allow\n                Action:\n                  - logs:CreateLogGroup\n                Resource: !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:*\n              - Effect: Allow\n                Action:\n                  - logs:CreateLogStream\n                  - logs:PutLogEvents\n                Resource: !Join\n                  - ''\n                  - - !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:\/aws\/lambda\/ssm-document-custom-function-\n                    - !Select [ '0', !Split [ '-', !Select [ '2', !Split [ '\/', !Ref AWS::StackId ] ] ] ]\n                    - :*\n\n  FunctionLog:\n    Type: AWS::Logs::LogGroup\n    Properties:\n      LogGroupName: !Join\n        - ''\n        - - \/aws\/lambda\/ssm-document-custom-function-\n          - !Select [ '0', !Split [ '-', !Select [ '2', !Split [ '\/', !Ref AWS::StackId ] ] ] ]\n      RetentionInDays: 7\n<\/pre>\n<p>\u672c\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u5229\u7528\u3057\u30b9\u30bf\u30c3\u30af\u3092\u4f5c\u6210\u3059\u308b\u3068\u3001\u30ea\u30bd\u30fc\u30b9\u306e\u6b04\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h38_25.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-21176\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h38_25-1024x434.png\" alt=\"\" width=\"728\" height=\"309\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h38_25-1024x434.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h38_25-300x127.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h38_25-768x325.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h38_25-728x308.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h38_25.png 1187w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a><br \/>\n\u30ed\u30b0\u30b9\u30c8\u30ea\u30fc\u30e0\u540d\u3067\u306f\u306a\u304f\u3001\u4efb\u610f\u306e\u5024\u3092\u7269\u7406ID\u3068\u3057\u3066\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4f55\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u305f\u306e\u304b\u3001\u30ed\u30b0\u30b9\u30c8\u30ea\u30fc\u30e0\u540d\u3088\u308a\u5206\u304b\u308a\u3084\u3059\u304f\u306a\u3063\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u30ab\u30b9\u30bf\u30e0\u30ea\u30bd\u30fc\u30b9\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3044\u3046\u3068\u3001\u4ee5\u4e0b\u306e\u9ec4\u6587\u5b57\u306e\u90e8\u5206\u3067\u7269\u7406ID\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>def lambda_handler(event, context):\n    try:\n        document_params = event['ResourceProperties']['DocumentParams']\n        account_id = event['StackId'].split(':')[4]\n        <span style=\"color: #ffff00;\">document_arn = f'arn:aws:ssm:{os.environ[\"AWS_REGION\"]}:{account_id}:document\/{document_params[\"Name\"]}'<\/span>\n\n        if event['RequestType'] in ['Create', 'Update']:\n            if document_exists(document_params):\n                update_document(document_params)\n            else:\n                create_document(document_params)\n\n        cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, <span style=\"color: #ffff00;\">physicalResourceId=document_arn<\/span>)\n<\/pre>\n<p>\u6b21\u306f\u3001\u672c\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u5229\u7528\u3057\u3066\u610f\u56f3\u7684\u306b\u30a8\u30e9\u30fc\u3092\u767a\u751f\u3055\u305b\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\nCFn \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u300cIdleSessionTimeout\u300d\u309261\u4ee5\u4e0a\u306e\u6570\u5024\u306b\u5909\u66f4\u3057\u3066\u307f\u307e\u3059\u3002<br \/>\n\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b CFn \u30b3\u30f3\u30bd\u30fc\u30eb\u4e0a\u306b\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h47_32-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-21182\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h47_32-1-1024x422.png\" alt=\"\" width=\"728\" height=\"300\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h47_32-1-1024x422.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h47_32-1-300x124.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h47_32-1-768x316.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h47_32-1-728x300.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2021\/11\/2021-11-24_15h47_32-1.png 1371w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a><\/p>\n<p>\u30ab\u30b9\u30bf\u30e0\u30ea\u30bd\u30fc\u30b9\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3044\u3046\u3068\u3001\u4ee5\u4e0b\u306e\u90e8\u5206\u3067\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8(Python \u306e\u30b9\u30bf\u30c3\u30af\u30c8\u30ec\u30fc\u30b9)\u3092\u53d6\u5f97\u3057\u3001\u9001\u4fe1\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>    except:\n        <span style=\"color: #ffff00;\">tb = traceback.format_exc()<\/span>\n        logger.error(tb)\n        cfnresponse.send(event, context, cfnresponse.FAILED, {}, physicalResourceId=None, noEcho=False, <span style=\"color: #ffff00;\">reason=tb.replace('\\n', r'\\n')<\/span>)\n<\/pre>\n<p>\u3053\u306e\u3084\u308a\u65b9\u306b\u306f2\u3064\u306e\u5229\u70b9\u304c\u3042\u308b\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u30ab\u30b9\u30bf\u30e0\u30ea\u30bd\u30fc\u30b9\u306e\u5b9f\u884c\u30ed\u30b0 (CloudWatch Logs) \u3092\u898b\u306b\u884c\u304b\u306a\u304f\u3066\u3082\u30a8\u30e9\u30fc\u5185\u5bb9\u304c\u5206\u304b\u308b<\/li>\n<li>CFn \u30b9\u30bf\u30c3\u30af\u521d\u56de\u4f5c\u6210\u6642\u306b\u30ab\u30b9\u30bf\u30e0\u30ea\u30bd\u30fc\u30b9\u5b9f\u884c\u304c\u5931\u6557\u3057\u3066\u3082\u30a8\u30e9\u30fc\u5185\u5bb9\u3092\u6b8b\u3057\u3066\u304a\u3051\u308b<\/li>\n<\/ol>\n<p>2\u70b9\u76ee\u306f\u3001CFn \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u3067\u30ab\u30b9\u30bf\u30e0\u30ea\u30bd\u30fc\u30b9\u7528Function \u306e\u30ed\u30b0\u30b0\u30eb\u30fc\u30d7\u3092\u4f5c\u6210\u3057\u3066\u3044\u308b\u5834\u5408\u306e\u8a71\u3067\u3059\u3002<br \/>\n\u30b9\u30bf\u30c3\u30af\u521d\u56de\u4f5c\u6210\u6642\u306b\u30ab\u30b9\u30bf\u30e0\u30ea\u30bd\u30fc\u30b9\u306e\u4f5c\u6210\u304c\u5931\u6557\u3059\u308b\u3068\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u306b\u3088\u308a\u5168\u30ea\u30bd\u30fc\u30b9\u304c\u524a\u9664\u3055\u308c\u308b\u305f\u3081\u3001\u30ab\u30b9\u30bf\u30e0\u30ea\u30bd\u30fc\u30b9\u7528Function \u306e\u30ed\u30b0\u30b0\u30eb\u30fc\u30d7\u307e\u3067\u6d88\u3048\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\n\u672c\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u3088\u3046\u306b cfn-response \u30e2\u30b8\u30e5\u30fc\u30eb \u3067\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u3057\u3066\u304a\u304f\u3053\u3068\u3067\u3001\u30ed\u30b0\u30b0\u30eb\u30fc\u30d7\u304c\u6d88\u3048\u3066\u3082 CFn \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u305d\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u6b8b\u3057\u3066\u304a\u3051\u308b\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u3002<\/p>\n<h1>\u304a\u307e\u3051<\/h1>\n<p>\u672c\u8a18\u4e8b\u3067\u7d39\u4ecb\u3057\u305f CFn \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u4f7f\u3063\u3066\u3044\u308b\u30ef\u30b6\u306a\u306e\u3067\u3059\u304c\u3001<br \/>\n<code>!Select [ '0', !Split [ '-', !Select [ '2', !Split [ '\/', !Ref AWS::StackId ] ] ] ]<\/code><br \/>\n\u3068\u66f8\u3044\u3066\u3042\u3052\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a StackId \u306e\u4e2d\u306e <strong>1234abcd<\/strong> \u307f\u305f\u3044\u306a\u6587\u5b57\u5217\u304c\u53d6\u5f97\u3067\u304d\u308b\u306e\u3067\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u3067\u306f\u306a\u3044\u30e9\u30f3\u30c0\u30e0\u6587\u5b57\u5217\u3092\u751f\u6210\u3059\u308b\u306e\u306b\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<pre>arn:aws:cloudformation:region:111122223333:stack\/stack-name\/<span style=\"color: #ffff00;\">1234abcd<\/span>-56ef-78gh-90ij-123456klmnop\n<\/pre>\n<p>\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u3046\u3068\u3001<code>ssm-document-custom-function-1234abcd<\/code> \u306e\u3088\u3046\u306a\u30ea\u30bd\u30fc\u30b9\u540d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>  Function:\n    Type: AWS::Lambda::Function\n    DependsOn: FunctionLog\n    Properties:\n      FunctionName: !Join\n        - ''\n        - - ssm-document-custom-function-\n          - !Select [ '0', !Split [ '-', !Select [ '2', !Split [ '\/', !Ref AWS::StackId ] ] ] ]\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 CloudFormation \u3067 Lambda-backed \u30ab\u30b9\u30bf\u30e0\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3059\u308b\u969b\u306b\u5229\u7528\u3059\u308b cfn-response \u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u3059\u304c\u3001\u5b9f\u4f53\u306f\u4ee5\u4e0b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002 cfn-response \u30e2&#8230;<\/p>\n","protected":false},"author":60,"featured_media":19252,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/www.skyarch.net\/blog\/?p=21169","footnotes":""},"categories":[20,1079,830],"tags":[102,542,549,65],"class_list":{"0":"post-21169","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-aws","8":"category-cloudformation","9":"category-systems-manager","10":"tag-aws","11":"tag-aws-cloudformation","12":"tag-aws-lambda","13":"tag-python","14":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/21169","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=21169"}],"version-history":[{"count":16,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/21169\/revisions"}],"predecessor-version":[{"id":21190,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/21169\/revisions\/21190"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/19252"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=21169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=21169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=21169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}