skip to Main Content

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.

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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 }}"
      - name: createTags
        action: aws:createTags
        maxAttempts: 2
        timeoutSeconds: 60
        onFailure: Abort
        inputs:
         ResourceType: EC2
         ResourceIds:
         - "{{ InstanceId }}"
         Tags:
         - Key: docker-installed
           Value: TRUE
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search