将参数添加到SSM维护窗口任务

发布于 2025-02-12 17:18:21 字数 1246 浏览 2 评论 0原文

我正在尝试通过在S3中执行脚本来使用SSM Run命令 - 我已经尝试对其进行编码,现在已经手动进行了所有作品。

我坚持将参数添加到SSM Manintenance窗口任务。

按照此示例 - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/docs/resources/ssm_maintance_window_task

这是下面的snippet。我正在添加3个参数,并计划/应用运行正常,但更改并未反映在控制台中!

 resource "aws_ssm_maintenance_window_task" "task" {
  max_concurrency = "2"
  max_errors      = "1"
  task_arn        = "AWS-RunRemoteScript"
  task_type       = "RUN_COMMAND"
  window_id       = aws_ssm_maintenance_window.taskuploadmaintenancewindow.id

  targets {
    key    = "WindowTargetIds"
    values = [aws_ssm_maintenance_window_target.taskuploadmaintenancewindowtarget.id]
  }

  task_invocation_parameters {
    run_command_parameters {
      parameter {
        name   = "SourceType"
        values = ["S3"]
      }
      parameter {
        name   = "SourceInfo"
        values = ["{\"path\":\"https://mybucket.s3.ap-northeast-1.amazonaws.com/myscript.sh\"}"]
      }
      parameter {
        name   = "commands"
        values = ["myscript.sh"]
      }
    }
  }

I'm trying to use the SSM Run Command by executing a script in S3 - I've tested this all works manually now I'm trying to code it.

I'm stuck with adding parameters to an SSM manintenance window task.

Following this example - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_maintenance_window_task

Here is the snippet below. I'm adding 3 parameters and plan/apply runs fine but the changes are not reflected in the console!

 resource "aws_ssm_maintenance_window_task" "task" {
  max_concurrency = "2"
  max_errors      = "1"
  task_arn        = "AWS-RunRemoteScript"
  task_type       = "RUN_COMMAND"
  window_id       = aws_ssm_maintenance_window.taskuploadmaintenancewindow.id

  targets {
    key    = "WindowTargetIds"
    values = [aws_ssm_maintenance_window_target.taskuploadmaintenancewindowtarget.id]
  }

  task_invocation_parameters {
    run_command_parameters {
      parameter {
        name   = "SourceType"
        values = ["S3"]
      }
      parameter {
        name   = "SourceInfo"
        values = ["{\"path\":\"https://mybucket.s3.ap-northeast-1.amazonaws.com/myscript.sh\"}"]
      }
      parameter {
        name   = "commands"
        values = ["myscript.sh"]
      }
    }
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半窗疏影 2025-02-19 17:18:21

解决了。 “命令”需要作为命令

行,我的工作方式是返回SSM Run命令,构建新命令并滚动到底部并查看AWS CLI CONFIC的语法,它为您构建:

  aws ssm send-command --document-name "AWS-RunRemoteScript" --document-version "1" --targets '[{"Key":"tag:Name","Values":["deliberately removed"]}]' --parameters '{"sourceType":["S3"],"sourceInfo":["{\"path\":\"https://mybucket.s3.ap-northeast-1.amazonaws.com/myscript.sh\"}"],"commandLine":["myscript.sh"],"workingDirectory":[""],"executionTimeout":["3600"]}' --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --region ap-northeast-1

因此,现在更改案例/命令行有效。我希望有一天对某人有帮助。

run_command_parameters {
      parameter {
        name   = "sourceType"
        values = ["S3"]
      }
      parameter {
        name   = "sourceInfo"
        values = ["{\"path\":\"https://mybucket.s3.ap-northeast-1.amazonaws.com/myscript.sh\"}"]
      }
      parameter {
        name   = "commandLine"
        values = ["myscript.sh"]

Worked it out.. It's a bit silly but those parameters need to be camel case & 'commands' needed to be commandLine

The way I worked this out was to go back into SSM Run Command, build out a new command and scroll to the bottom and review the syntax of the AWS CLI config it builds for you:

  aws ssm send-command --document-name "AWS-RunRemoteScript" --document-version "1" --targets '[{"Key":"tag:Name","Values":["deliberately removed"]}]' --parameters '{"sourceType":["S3"],"sourceInfo":["{\"path\":\"https://mybucket.s3.ap-northeast-1.amazonaws.com/myscript.sh\"}"],"commandLine":["myscript.sh"],"workingDirectory":[""],"executionTimeout":["3600"]}' --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --region ap-northeast-1

So now changing the case/commandLine works. I hope this helps someone one day.

run_command_parameters {
      parameter {
        name   = "sourceType"
        values = ["S3"]
      }
      parameter {
        name   = "sourceInfo"
        values = ["{\"path\":\"https://mybucket.s3.ap-northeast-1.amazonaws.com/myscript.sh\"}"]
      }
      parameter {
        name   = "commandLine"
        values = ["myscript.sh"]
苏辞 2025-02-19 17:18:21

顺便说一句,我发现输入SourceInfo时没有处理可怕的格式,而是可以将其包装在Terraform的Jsonencode中。

  parameter {
    name = "sourceInfo"
    values = [jsonencode(
      {
        owner      = "ownername"
        path       = "pathdir"
        repository = "reponame"
        tokenInfo  = "sometoken"
      }
      )
    ]
  }

By the way, I found out that instead of dealing with the horrendous format when inputting sourceInfo, you can wrap it in jsonencode in Terraform.

  parameter {
    name = "sourceInfo"
    values = [jsonencode(
      {
        owner      = "ownername"
        path       = "pathdir"
        repository = "reponame"
        tokenInfo  = "sometoken"
      }
      )
    ]
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文