如何使用downloadContent sourceInfo StringMap在AWS System Manager文档中正确格式化语法 [英] How do you properly format the syntax in an AWS System Manager Document using downloadContent sourceInfo StringMap

查看:162
本文介绍了如何使用downloadContent sourceInfo StringMap在AWS System Manager文档中正确格式化语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是让AWS System Manager文档从S3下载脚本,然后在选定的EC2实例上运行该脚本.在这种情况下,它将是Linux操作系统.

My goal is to have an AWS System Manager Document download a script from S3 and then run that script on the selected EC2 instance. In this case, it will be a Linux OS.

根据 AWS文档aws:downloadContent sourceInfo输入的类型为StringMap.

According to AWS documentation for aws:downloadContent the sourceInfo Input is of type StringMap.

示例代码如下:

{
  "schemaVersion": "2.2",
  "description": "aws:downloadContent",
  "parameters": {
    "sourceType": {
    "description": "(Required) The download source.",
    "type": "String"
  },
  "sourceInfo": {
    "description": "(Required) The information required to retrieve the content from the required source.",
    "type": "StringMap"
    }
  },
  "mainSteps": [
    {
      "action": "aws:downloadContent",
      "name": "downloadContent",
      "inputs": {
        "sourceType":"{{ sourceType }}",
        "sourceInfo":"{{ sourceInfo }}"
      }
    }
  ]
}

此代码假定您将手动运行此文档(控制台或CLI),然后在参数中输入sourceInfo.手动运行此文档时,不接受在参数(S3 URL)中输入的任何内容.但是,我并不是要手动运行它,而是要以编程方式运行,并且我想在mainSteps中将S3 URL硬编码为sourceInfo.

This code assumes you will run this document by hand (console or CLI) and then enter the sourceInfo in the parameter. When running this document by hand, anything entered in the parameter (an S3 URL) isn't accepted. However, I'm not trying to run this by hand, but rather programmatically and I want to hard code the S3 URL into sourceInfo in mainSteps.

AWS确实提供了一个语法示例,如下所示:

AWS does give an example of syntax that looks like this:

{
"path": "https://s3.amazonaws.com/aws-executecommand-test/powershell/helloPowershell.ps1" 
}

我已经在mainSteps中对文档操作进行了编码,如下所示:

I've coded the document action in mainSteps like this:

        {
            "action": "aws:downloadContent",
            "name": "downloadContent",
            "inputs": {
              "sourceType": "S3",
              "sourceInfo":
                {
                  "path": "https://s3.amazonaws.com/bucketname/folder1/folder2/script.sh"
                },
                "destinationPath": "/tmp"
            }
        },

但是,它似乎不起作用,并且我收到此错误:

However, it doesn't seem to work and I receive this error:

插件属性map中无效的格式map [sourceInfo:map [path:https://s3.amazonaws.com/bucketname/folder1/folder2/script.sh] sourceType:S3];错误json:无法将对象解组到字符串类型的Go结构字段DownloadContentPlugin.sourceInfo

注意:我已经看过帖子,其中提到了如何在Windows上对其进行格式化.我做了尝试,没有用,而且似乎与我的Linux需求无关.

Note: I have seen this post that references how to format it for Windows. I did try it, didn't work and doesn't seem relevant to my Linux needs.

所以我的问题是:

  1. 您是否需要StringMap类型的sourceInfo参数-aws:downloadContent {{sourceInfo}} mainSteps中不会使用的参数?
  2. 您如何在mainSteps中正确设置aws:downloadContent操作sourceInfo StringMap的格式?

谢谢您的努力.

推荐答案

我遇到了类似的问题,因为我不希望任何人在运行时键入内容.因此,我为下载内容添加了默认设置

I had similar issue as I did not want anyone to type the stuff when running. So I added a default to the download content

    "sourceInfo": {
  "description": "(Required) Blah.",
  "type": "StringMap",
  "displayType": "textarea",
  "default": {
    "path": "https://mybucket-public.s3-us-west-2.amazonaws.com/automation.sh"
  }
}

这篇关于如何使用downloadContent sourceInfo StringMap在AWS System Manager文档中正确格式化语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆