すべてのプロダクト
Search
ドキュメントセンター

Resource Orchestration Service:Fn::GetJsonValue

最終更新日:Jan 16, 2025

組み込み関数 Fn::GetJsonValue は、JSON 文字列を解決し、最初の層からキーの値をクエリします。

宣言

  • JSON

    {
      "Fn::GetJsonValue": [
        "key",
        "json_string"
      ]
    }
  • YAML

    • 完全な関数名の構文:

      Fn::GetJsonValue:
       - key
       - json_string
    • 短縮形の構文:

      !GetJsonValue [key, json_string]

パラメーター

  • key: キー値。

  • json_string: 解決する JSON 文字列。

次の例では、WebServer インスタンスが UserData を実行し、JSON 文字列を返します。次に、WebServer2 インスタンスが文字列からキー値をクエリします。

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  WebServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-2ze45uwova5fedlu****
      InstanceType: ecs.n1.medium
      SecurityGroupId: sg-2ze7pxymaix640qr****
      Password: Wenqiao****
      IoOptimized: optimized
      VSwitchId: vsw-2zei67xd9nhcqxzec****
      VpcId: vpc-2zevx9ios1rszqv0a****
      SystemDiskCategory: cloud_ssd
      UserData:
        Fn::Replace:
          - ros-notify:
              Fn::GetAtt:
                - WaitConHandle
                - CurlCli
          - Fn::Join:
              - ''
              - - |
                  #!/bin/sh
                - |
                  mkdir ~/test_ros
                - |
                  print hello > ~/1.txt
                - |
                  cmd="ros-notify -d '{\"id\" : \"1\", \"data\" : [\"1111\", \"2222\"]}'"
                - |
                  eval $cmd
      PrivateIpAddress: 192.168.XX.XX
      HostName: userdata-1
  WaitConHandle:
    Type: ALIYUN::ROS::WaitConditionHandle
  WaitCondition:
    Type: ALIYUN::ROS::WaitCondition
    Properties:
      Handle:
        Ref: WaitConHandle
      Timeout: 900
  WebServer2:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-2ze45uwova5fedlu****
      InstanceType: ecs.n1.medium
      SecurityGroupId: sg-2ze7pxymaix640qr****
      Password: Wenqiao****
      IoOptimized: optimized
      VSwitchId: vsw-2zei67xd9nhcqxzec****
      VpcId: vpc-2zevx9ios1rszqv0a****
      SystemDiskCategory: cloud_ssd
      UserData:
        Fn::Join:
          - ''
          - - |
              #!/bin/sh
            - |
              mkdir ~/test_ros
            - |
              echo hello > ~/1.txt
            - server_1_token=
            - !GetJsonValue
                - '1 '
                - !GetAtt WaitCondition.Data
            - |+
      PrivateIpAddress: 192.168.XX.XX
      HostName: userdata-2
Outputs:
  InstanceId:
    Value: !GetAtt WebServer.InstanceId
  PublicIp:
    Value: !GetAtt WebServer.PublicIp

サポートされている関数