Skip to content

Unattended SAM CLI install on EC2 via CFn userdata? #1900

@mrichman

Description

@mrichman

I have a use case where I'd like to install the SAM CLI on an EC2 instance via CloudFormation userdata. This is for a lab environment.

The first snag I'm hitting is the installation of Linuxbrew

sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"

which prompts to Press RETURN to continue or any other key to abort. It also warns not to run as root.

So the issue here is that because the install will run in userdata, it's running as root. It would need to install as root, but into a different (predefined) user's environment.

Is there any guidance on performing an unattended install of SAM CLI, and possibly on a systemwide basis?

A standard yum package would be wonderful.

So far, this kind of thing seems to work (Amazon Linux 2):

UserData:
        Fn::Base64: |
          #!/bin/bash -xe
          yum update -y
          yum groupinstall 'Development Tools' -y
          git clone https://github.com/Homebrew/brew /home/linuxbrew/.linuxbrew/Homebrew
          mkdir /home/linuxbrew/.linuxbrew/bin
          ln -s /home/linuxbrew/.linuxbrew/Homebrew/bin/brew /home/linuxbrew/.linuxbrew/bin
          chown -R labuser /home/linuxbrew/
          /home/linuxbrew/.linuxbrew/bin/brew shellenv >> ~labuser/.bash_profile
          brew config
          brew tap aws/tap
          brew install aws-sam-cli
          sam --version

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions