All Products
Search
Document Center

CloudOps Orchestration Service:ACS::ExecuteHttpRequest

Last Updated:May 16, 2024

Description

The ACS::ExecuteHttpRequest action can be used to call external API operations by using HTTP or HTTPS requests during O&M tasks. This way, O&M tasks performed on Alibaba Cloud resources can interact with external HTTP services.

The ACS::ExecuteHttpRequest action can be used in the following scenarios:

  1. API integration: You can use the ACS::ExecuteHttpRequest action to call the APIs of third-party services to query information, perform operations, or integrate third-party services.

  2. Custom notification: If you want to send a notification at a specific stage during script execution, you can use the ACS::ExecuteHttpRequest action to send an HTTP request to the specified webhook or notification service. This way, the notification can be sent by email, text message, or push notification.

  3. Data collection and reporting: You can use the ACS::ExecuteHttpRequest action to send the information about an O&M task to a remote server or data platform for auditing, monitoring, and reporting.

  4. Automated process triggering: You can use the ACS::ExecuteHttpRequest action to trigger the execution of other automated tools or scripts when a CloudOps Orchestration Service (OOS) template is being executed. For example, you can start the deployment process in a continuous integration or continuous deployment (CI/CD) system or start O&M tasks in other external systems.

  5. External verification and authorization: You may need to authenticate identities and verify operation permissions during the O&M process. In this case, you can use the ACS::ExecuteHttpRequest action to send a request to an external authentication system to verify the identity of the operator or verify the required operation permissions.

Syntax

Tasks:
  - Name: executeHttpRequestExample
    Action: ACS::ExecuteHttpRequest
    Properties:
      Method: POST # Optional. The HTTP method used to submit the request. Valid values: POST and GET. Default value: POST.
      URL: 'https://example.com' # Required. The HTTP URL used to specify the location of a specific resource.
      Headers: # Optional. The HTTP request headers.
        Content-Type: 'application/json'
      Query: # Optional. The HTTP request parameters.
        Parameter1: value1
        Parameter2: value2
      Body: # Optional. The HTTP request body. This parameter is valid only if the HTTP method is POST.
        Parameter3: value3
        Parameter4: value4
    Outputs:
      OutputParameter1:
        ValueSelector: 'jq selector' # The jQuery selector for selecting the data to return. The jQuery selector extracts information from the JSON data returned by the API operation. For more information about the jq syntax, visit https://stedolan.github.io/jq/.
        Type: String/Boolean/List/Number/Object
{
  "Tasks": [
    {
      "Name": "executeHttpRequestExample",
      "Action": "ACS::ExecuteHttpRequest",
      "Properties": {
        "Method": "POST",
        "URL": "https://example.com",
        "Headers": {
          "Content-Type": "application/json"
        },
        "Query": {
          "Parameter1": "Value1",
          "Parameter2": "Value2"
        },
        "Body": {
          "Parameter3": "Value3",
          "Parameter4": "Value4"
        }
      },
      "Outputs": {
        "OutputParameter1": {
          "ValueSelector": "jq selector",
          "Type": "String/Boolean/List(Array)/Number/Object"
        }
      }
    }
  ]
}

Examples

The following sample code provides examples on how to submit an HTTP request to specify the code branches to be used in an OOS template that is used to deploy the specified Elastic Compute Service (ECS) instance by triggering GitHub Actions:

FormatVersion: OOS-2019-06-01
Description: 
    en: OOS template for deploying ECS instances using GitHub Actions.
     
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
       
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  targets:
    Type: Json
    Label:
      en: TargetInstance
       
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: regionId
      Status: Running
  gitHubBranch:
    Type: String
    Description:
        en: Branch where the deployment will occur.
         
Tasks:
  - Name: getInstance
    Description:
      en: Views the ECS instances
       
    Action: ACS::SelectTargets
    Properties:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: '{{ regionId }}'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: Instances.Instance[].InstanceId
  - Name: DeployCodeByGitHubAction
    Action: ACS::ExecuteHttpRequest
    Properties:
      Method: POST
      URL: "https://api.github.com/repos/<YOUR-GITHUB-ACCOUNT>/<YOUR-GITHUB-REPO>/actions/workflows/<YOUR-WORKFLOW-ID>/dispatches"
      Headers:
        Accept: application/vnd.github+json
        Authorization: "Bearer <YOUR-TOKEN>"
        X-GitHub-Api-Version: 2022-11-28
      Body: 
        ref: "{{gitHubBranch}}"
        inputs:
          instance_ids: "{{getInstance.instanceIds}}"
{
  "FormatVersion": "OOS-2019-06-01",
  "Description": {
    "en": "OOS template for deploying ECS instances using GitHub Actions.",
     
  },
  "Parameters": {
    "regionId": {
      "Type": "String",
      "Label": {
        "en": "RegionId",
         
      },
      "AssociationProperty": "RegionId",
      "Default": "{{ ACS::RegionId }}"
    },
    "targets": {
      "Type": "Json",
      "Label": {
        "en": "TargetInstance",
         
      },
      "AssociationProperty": "Targets",
      "AssociationPropertyMetadata": {
        "ResourceType": "ALIYUN::ECS::Instance",
        "RegionId": "regionId",
        "Status": "Running"
      }
    },
    "gitHubBranch": {
      "Type": "String",
      "Description": {
        "en": "Branch where the deployment will occur.",
         
      }
    }
  },
  "Tasks": [
    {
      "Name": "getInstance",
      "Description": {
        "en": "Views the ECS instances",
         
      },
      "Action": "ACS::SelectTargets",
      "Properties": {
        "ResourceType": "ALIYUN::ECS::Instance",
        "RegionId": "{{ regionId }}",
        "Filters": [
          "{{ targets }}"
        ]
      },
      "Outputs": {
        "instanceIds": {
          "Type": "List",
          "ValueSelector": "Instances.Instance[].InstanceId"
        }
      }
    },
    {
      "Name": "DeployCodeByGitHubAction",
      "Action": "ACS::ExecuteHttpRequest",
      "Properties": {
        "Method": "POST",
        "URL": "https://api.github.com/repos/<YOUR-GITHUB-ACCOUNT>/<YOUR-GITHUB-REPO>/actions/workflows/<YOUR-WORKFLOW-ID>/dispatches",
        "Headers": {
          "Accept": "application/vnd.github+json",
          "Authorization": "Bearer <YOUR-TOKEN>",
          "X-GitHub-Api-Version": "2022-11-28T00:00:00.000Z"
        },
        "Body": {
          "ref": "{{gitHubBranch}}",
          "inputs": {
            "instance_ids": "{{getInstance.instanceIds}}"
          }
        },
        "Query": {}
      }
    }
  ]
}