【问题标题】:AWS Cloudformation SSM automation document | use with aws cloudformation packageAWS Cloudformation SSM 自动化文档 |与 aws cloudformation 包一起使用
【发布时间】:2020-10-27 03:06:13
【问题描述】:

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

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

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

例如,代替commands: 下的Restart-Computer -Force 行,我想使用如下外部脚本(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"
[...]

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

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-cloudformation aws-cli aws-systems-manager


    【解决方案1】:

    有一个命令文档叫做AWS-RunRemoteScript:

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

    但是,如果您希望 CLI 自动将本地文件上传到 S3,就像对 lambda 所做的那样,那么遗憾的是,SSM 文档不支持此功能。仅following 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-03-08
      • 1970-01-01
      • 1970-01-01
      • 2020-05-12
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      相关资源
      最近更新 更多