Search code examples
amazon-web-servicesamazon-ec2aws-ssm

AWS EC2 Image Builder: How to prevent removing SSM Agent


I need to prepare an AMI based on CentOS 8 with pre-installed SSM-agent. Trying to use Image Builder for this. According to the documentation:

Instances used to build images and run tests using Image Builder must have access to the Systems Manager service. All build activity is orchestrated by SSM Automation. The SSM Agent will be installed on the source image if it is not already present, and it will be removed before the image is created.

So the question is how to prevent removing of SSM-agent? I need to keep it installed. Unfortunately couldn't find a solution in the documentation.


Solution

  • ImageBuilder installs the SSM agent if SSM is not present in the source AMI and uninstalls the agent before taking the AMI. When ImageBuilder installs the SSM agent, it keeps track of the installation of the agent(in a file) and it is located at/tmp/imagebuilder_service/ssm_installed. you just need to remove that file as part of your build, then it won't remove the SSM agent.

    Add an extra step in the Imagebuilder build component to retain the SSM agent installation

    - name: RetainSSMAgentInstallation
        action: ExecuteBash
        inputs:
          commands:
            - sudo rm -rf /tmp/imagebuilder_service/ssm_installed