ACS-ECS-DownloadFileFromECS

Updated at:

Template name

ACS-ECS-DownloadFileFromECS: Download a file from an ECS instance

Execute now

Template description

Uploads a file from an ECS instance to OSS and generates a temporary download URL.

Template type

Automation

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Constraints

instanceId

The ID of the ECS instance.

String

Yes

fileName

The path of the file to download.

String

Yes

bucketName

The OSS bucket for temporary storage.

String

Yes

regionId

The region ID.

String

No

{{ ACS::RegionId }}

Output parameters

Parameter

Description

Type

temporaryUrl

String

commandOutput

String

Required access policy

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeInstances",
                "ecs:DescribeInvocationResults",
                "ecs:DescribeInvocations",
                "ecs:RunCommand"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "oss:GetObject",
                "oss:PutObjectACL"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

Details

Details of ACS-ECS-DownloadFileFromECS

Template content

FormatVersion: OOS-2019-06-01
Description:
  name-en: ACS-ECS-DownloadFileFromECS
  name-zh-cn: Download a file from an ECS instance
  en: Upload ECS files to OSS and generate temporary download links
  zh-cn: Uploads a file from an ECS instance to OSS and generates a temporary download URL.
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: Region ID
    AssociationProperty: ALIYUN::ECS::RegionId
    Default: '{{ ACS::RegionId }}'
  instanceId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::InstanceId
    Label:
      en: ECS Instance Id
      zh-cn: ECS instance
    AssociationPropertyMetadata:
      RegionId: regionId
  fileName:
    Type: String
    Label:
      en: File to be downloaded
      zh-cn: File to download
    Description:
      en: The path of the file to be downloaded on the ecs, such as /root/your_file.zip (linux), C:\\Users\\Administrator\\your_file.zip (windows)
      zh-cn: The path of the file to download from the ECS instance. For example, /root/your_file.zip for Linux, or C:\\Users\\Administrator\\your_file.zip for Windows. Use double backslashes for Windows paths.
  bucketName:
    Type: String
    AssociationProperty: ALIYUN::OSS::Bucket::BucketName
    AssociationPropertyMetadata:
      RegionId: regionId
    Label:
      en: OSS bucket for temporary storage
      zh-cn: OSS bucket for temporary storage
    Description:
      en: Select your existing OSS Bucket from the drop-down list. The files to be downloaded will be uploaded to the /aliyun_download_file directory in the Bucket for subsequent downloads. You can delete it after downloading.
      zh-cn: Select an existing OSS bucket. The file is uploaded to the /aliyun_download_file directory in the bucket for you to download. You can delete the file after the download is complete.
Tasks:
  - Action: ACS::ECS::UploadOssFile
    Name: UploadOssFile
    Description:
      en: Upload OSS file
      zh-cn: Upload the OSS file
    Properties:
      regionId: '{{ regionId }}'
      ossRegion: '{{ regionId }}'
      validTime: 900
      uploadWaitingTime: 3600
      objectName:
        Fn::Join:
          - /
          - - aliyun_download_file/{{ ACS::ExecutionId }}
            - Fn::Select:
              - -1
              - Fn::If:
                  - Fn::ContainsSubString:
                      - '{{ fileName }}'
                      - /
                  - Fn::Split:
                      - /
                      - '{{ fileName }}'
                  - Fn::Split:
                      - \\
                      - '{{ fileName }}'
      bucketName: '{{ bucketName }}'
      fileToUpload: '{{ fileName }}'
      instanceId: '{{ instanceId }}'
  - Name: PutObjectACL
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Put object ACL
      zh-cn: Set object permissions
    Properties:
      Service: OSS
      API: PutObjectACL
      Headers:
        x-oss-object-acl: private
      Parameters:
        BucketName: '{{ bucketName }}'
        RegionId: '{{ regionId }}'
        key:
          Fn::Join:
            - /
            - - aliyun_download_file/{{ ACS::ExecutionId }}
              - Fn::Select:
                  - -1
                  - Fn::If:
                      - Fn::ContainsSubString:
                          - '{{ fileName }}'
                          - /
                      - Fn::Split:
                          - /
                          - '{{ fileName }}'
                      - Fn::Split:
                          - \\
                          - '{{ fileName }}'
  - Action: ACS::OSS::GenerateUrl
    Name: GenerateUrl
    Description:
      en: generate temporary download url
      zh-cn: Generate a temporary download URL
    Properties:
      regionId: '{{ regionId }}'
      validTime: 600
      isInternal: false
      bucketName: '{{ bucketName }}'
      objectName:
        Fn::Join:
          - /
          - - aliyun_download_file/{{ ACS::ExecutionId }}
            - Fn::Select:
                - -1
                - Fn::If:
                    - Fn::ContainsSubString:
                        - '{{ fileName }}'
                        - /
                    - Fn::Split:
                        - /
                        - '{{ fileName }}'
                    - Fn::Split:
                        - \\
                        - '{{ fileName }}'
    Outputs:
      temporaryUrl:
        Type: String
        ValueSelector: temporaryUrl
Outputs:
  temporaryUrl:
    Type: String
    Value: '{{ GenerateUrl.temporaryUrl }}'
  commandOutput:
    Type: String
    Value: '{{ UploadOssFile.commandOutput }}'