2

in AWS Cloudformation I could use the cloudformation package command via CLI. This works for example with Lambdas:

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

Now, I would like to to the same like Code: lambda/helloWorld.py within Systems Manager automation documents.

For example instead of the line Restart-Computer -Force under commands: I would like to use external skripts like this below (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"
[...]

Do you know any possibility to realize this? Thanks in advance!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
user39419
  • 45
  • 6

1 Answers1

1

There is command documment called AWS-RunRemoteScript:

You can run SSM documents from remote locations by using the AWS-RunDocument pre-defined SSM document. This document currently supports the following remote locations: GitHub repositories (public and private), Amazon S3, Documents saved in Systems Manager

However, if you want the CLI to automatically upload your local file to S3, like it does for lambda, then this functionality is sadly not supported for SSM documents. The automatic upload of local artifacts is only supported for the following CFN resource types:

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
Marcin
  • 215,873
  • 14
  • 235
  • 294