Home > Back-end >  AWS SSM CreateDocument operation: Parameter "InstanceId" is not declared
AWS SSM CreateDocument operation: Parameter "InstanceId" is not declared

Time:07-11

I am learning AWS and while creating a SSM document i'm not getting IntanceID while trying to create a SSM Document, I am using below aws cli and yaml to get the same.

SSM Coommnad:

aws ssm create-document --name "SSM Document-test" --content file://installtest.yml --document-type "test" --document-format YAML --region us-east-1

Below is

description: Installs Docker on the Instance and tag it properly
schemaVersion: '0.3'
parameters:
  instanceId:
    type: String
    description: "Instance ID of an instance to install Docker to"
  build:
    type: String
    description: "The build of docker to install"
    default: "get" # default version
mainSteps:
  - name: AssertRunning
    action: aws:assertAwsResourceProperty
    isCritical: true
    onFailure: step:abort
    nextStep: installPackages
    inputs:
      Service: ec2
      Api: DescribeInstnaces
      InstanceIds:
        - "{{InstanceId}}"
      PropertySelctor: ".$Reservation[0].Instances[0],State.Name"
      DesiredValues:
        - running

Inspiration from re-invent

any help will be much appreciated.

CodePudding user response:

You have 2 typos. Api: DescribeInstnaces and PropertySelctor: ".$Reservation[0].Instances[0],State.Name".

Try this:

description: Installs Docker on the Instance and tag it properly
schemaVersion: '0.3'
parameters:
  instanceId:
    type: String
    description: "Instance ID of an instance to install Docker to"
  build:
    type: String
    description: "The build of docker to install"
    default: "get" # default version
mainSteps:
  - name: AssertRunning
    action: aws:assertAwsResourceProperty
    isCritical: true
    onFailure: step:abort
    nextStep: installPackages
    inputs:
      Service: ec2
      Api: DescribeInstances
      InstanceIds:
        - "{{ InstanceId }}"
      PropertySelector: "$.Reservation[0].Instances[0].State.Name"
      DesiredValues:
        - running

CodePudding user response:

Adding another answer to make it clear. You can create Command or Automation based on your needs.

Refer SSM Document schema

** Working Example for Automation:**

cli : aws ssm create-document --name "SSM-Document-test" --content file://SSM-Document-Test.yaml --document-type "Automation" --document-format YAML --region us-east-1

description: Installs Docker on the Instance and tag it properly
schemaVersion: '0.3'
parameters:
  InstanceId:
    type: String
    description: "Instance ID of an instance to install Docker to"
  build:
    type: String
    description: "The build of docker to install"
    default: "get" # default version
mainSteps:
  - name: AssertRunning
    action: aws:assertAwsResourceProperty
    isCritical: true
    onFailure: Abort
    inputs:
      Service: ec2
      Api: DescribeInstances
      InstanceIds:
        - "{{ InstanceId }}"
      PropertySelector: "$.Reservation[0].Instances[0].State.Name"
      DesiredValues:
        - running
  - name: installPackages
    action: aws:runCommand
    inputs:
      DocumentName: SSM-Document-Test
      InstanceIds:
        - "{{ InstanceId }}"
      Parameters:
        build:
          - "{{ build }}"
  • Related