2

在 AWS Cloudformation 中,我可以cloudformation package通过 CLI 使用该命令。例如,这适用于 Lambda:

lambda:
    Type: AWS::Lambda::Function
    Properties:
      Handler: helloWorld.lambda_handler
      Role: !GetAtt lambda.Arn
      Code: lambda/helloWorld.py

现在,我想Code: lambda/helloWorld.py在 Systems Manager 中像自动化文档一样。

例如,我想使用下面这样的外部脚本,而不是下面的行(Restart-Computer -Force):commands:commands: scripts/restart.ps1

#---Original

[...]
- name: restartEC2Instance
action: aws:runCommand
maxAttempts: 3
timeoutSeconds: 600
inputs:
  DocumentName: AWS-RunPowerShellScript
  InstanceIds:
    - "{{ InstanceId }}"
  Parameters:
    commands: |
      Restart-Computer -Force
    executionTimeout: "600"
[...]

#---Desired

[...]
- name: restartEC2Instance
action: aws:runCommand
maxAttempts: 3
timeoutSeconds: 600
inputs:
  DocumentName: AWS-RunPowerShellScript
  InstanceIds:
    - "{{ InstanceId }}"
  Parameters:
    commands: scripts/restart.ps1
    executionTimeout: "600"
[...]

您知道实现这一点的任何可能性吗?提前致谢!

4

1 回答 1

1

有一个名为AWS-RunRemoteScript的命令文档:

您可以使用 AWS-RunDocument 预定义的 SSM文档从远程位置运行 SSM 文档。本文档当前支持以下远程位置:GitHub 存储库(公共和私有)、Amazon S3、保存在 Systems Manager 中的文档

但是,如果您希望 CLI 自动将本地文件上传到 S3,就像对 lambda 所做的那样,那么遗憾的是,SSM文档不支持此功能。以下CFN 资源类型支持自动上传本地工件:

BodyS3Location property for the AWS::ApiGateway::RestApi resource
Code property for the AWS::Lambda::Function resource
CodeUri property for the AWS::Serverless::Function resource
DefinitionS3Location property for the AWS::AppSync::GraphQLSchema resource
RequestMappingTemplateS3Location property for the AWS::AppSync::Resolver resource
ResponseMappingTemplateS3Location property for the AWS::AppSync::Resolver resource
DefinitionUri property for the AWS::Serverless::Api resource
Location parameter for the AWS::Include transform
SourceBundle property for the AWS::ElasticBeanstalk::ApplicationVersion resource
TemplateURL property for the AWS::CloudFormation::Stack resource
Command.ScriptLocation property for the AWS::Glue::Job resource
DefinitionS3Location property for the AWS::StepFunctions::StateMachine resource
于 2020-07-06T22:54:47.043 回答