Amazon-ssm-agent: CloudFormation installation

Created on 10 Aug 2017  路  3Comments  路  Source: aws/amazon-ssm-agent

Hi,

Is it possible to install the agent via the AWS::CloudFormation::Init CloudFormation template section, like this:

Metadata:
  AWS::CloudFormation::Init:
    config:
      services:
        sysvinit:
          amazon-ssm-agent:
            enabled: true
            ensureRunning: true
            packages:
              apt:
                amazon-ssm-agent: https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb

??

I tried and here's the errors I have in /var/log/cfn-init.log file:

017-08-09 19:08:55,489 [DEBUG] Using service modifier: /usr/sbin/update-rc.d
2017-08-09 19:08:55,489 [DEBUG] Setting service amazon-ssm-agent to enabled
2017-08-09 19:08:55,826 [ERROR] update-rc.d failed with error 1. Output: update-rc.d: error: cannot find a LSB script for amazon-ssm-agent

2017-08-09 19:08:55,826 [ERROR] Error encountered during build of config: Could not enable service amazon-ssm-agent (return code 1)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/construction.py", line 517, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/construction.py", line 258, in build
    CloudFormationCarpenter._serviceTools[manager]().apply(services, changes)
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/service_tools.py", line 155, in apply
    self._set_service_enabled(service, util.interpret_boolean(serviceProperties["enabled"]))
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/service_tools.py", line 234, in _set_service_enabled
    modifier.set_service_enabled(service, enabled);
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/service_tools.py", line 324, in set_service_enabled
    raise ToolError("Could not %s service %s" % ("enable" if enabled else "disable", service), result.returncode)
ToolError: Could not enable service amazon-ssm-agent (return code 1)
2017-08-09 19:08:55,829 [ERROR] -----------------------BUILD FAILED!------------------------
2017-08-09 19:08:55,829 [ERROR] Unhandled exception during build: Could not enable service amazon-ssm-agent (return code 1)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/EGG-INFO/scripts/cfn-init", line 171, in <module>
    worklog.build(metadata, configSets)
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/construction.py", line 118, in build
    Contractor(metadata).build(configSets, self)
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/construction.py", line 505, in build
    self.run_config(config, worklog)
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/construction.py", line 517, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/construction.py", line 258, in build
    CloudFormationCarpenter._serviceTools[manager]().apply(services, changes)
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/service_tools.py", line 155, in apply
    self._set_service_enabled(service, util.interpret_boolean(serviceProperties["enabled"]))
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/service_tools.py", line 234, in _set_service_enabled
    modifier.set_service_enabled(service, enabled);
  File "/usr/local/lib/python2.7/dist-packages/aws_cfn_bootstrap-1.4-py2.7.egg/cfnbootstrap/service_tools.py", line 324, in set_service_enabled
    raise ToolError("Could not %s service %s" % ("enable" if enabled else "disable", service), result.returncode)
ToolError: Could not enable service amazon-ssm-agent (return code 1)
^C

Most helpful comment

@macktab @nefilim I had the same error with sysvinit after AMI to latest Amazon Linux 2 (ecs optimised).
However the service name changed with systemd from awslogs to awslogsd (link)

Error:
[ 26.345967] cloud-init[4276]: Error occurred during build: Could not enable service awslogs (return code 1)

Before

Metadata:
            AWS::CloudFormation::Init:
                config:
                    packages:
                        yum:
                            awslogs: []
[SNIP]
                    services:
                        sysvinit:
                            awslogs:
                                enabled: true
                                ensureRunning: true
                                files:
                                    - /etc/awslogs/awslogs.conf
                                    - /etc/awslogs/awscli.conf

After

Metadata:
            AWS::CloudFormation::Init:
                config:
                    packages:
                        yum:
                            awslogs: []
[SNIP]
                    services:
                        sysvinit:
                            awslogsd:
                                enabled: true
                                ensureRunning: true
                                files:
                                    - /etc/awslogs/awslogs.conf
                                    - /etc/awslogs/awscli.conf

All 3 comments

    setup-aws-ssm-agent:
      files:
        '/tmp/amazon-ssm-agent.deb':
          source: !Sub 'https://amazon-ssm-${AWS::Region}.s3.amazonaws.com/latest/debian_amd64/amazon-ssm-agent.deb'
          mode: '000644'
          owner: root
          group: root
      commands:
        00_setup_aws_ssm_agent:
          command: !Sub |
            dpkg -i /tmp/amazon-ssm-agent.deb
            systemctl enable amazon-ssm-agent.service
            service amazon-ssm-agent restart

This is somewhat silly, ran into the same problem with awslogs, which uses systemd, not sysv.

chkconfig heralds from the sysv days, doesn't support systemd services, I don't know why Cloudformation still doesn't appear to support systemd services?

So as @macktab showed, you have to enable & start your service yourself and NOT use the sysvinit stanza for these services.

@macktab @nefilim I had the same error with sysvinit after AMI to latest Amazon Linux 2 (ecs optimised).
However the service name changed with systemd from awslogs to awslogsd (link)

Error:
[ 26.345967] cloud-init[4276]: Error occurred during build: Could not enable service awslogs (return code 1)

Before

Metadata:
            AWS::CloudFormation::Init:
                config:
                    packages:
                        yum:
                            awslogs: []
[SNIP]
                    services:
                        sysvinit:
                            awslogs:
                                enabled: true
                                ensureRunning: true
                                files:
                                    - /etc/awslogs/awslogs.conf
                                    - /etc/awslogs/awscli.conf

After

Metadata:
            AWS::CloudFormation::Init:
                config:
                    packages:
                        yum:
                            awslogs: []
[SNIP]
                    services:
                        sysvinit:
                            awslogsd:
                                enabled: true
                                ensureRunning: true
                                files:
                                    - /etc/awslogs/awslogs.conf
                                    - /etc/awslogs/awscli.conf
Was this page helpful?
0 / 5 - 0 ratings