Skip to content

Instantly share code, notes, and snippets.

@oraculix
Last active March 10, 2023 16:01
Show Gist options
  • Save oraculix/c8e227cbe8ad190dfda1a44d6566b716 to your computer and use it in GitHub Desktop.
Save oraculix/c8e227cbe8ad190dfda1a44d6566b716 to your computer and use it in GitHub Desktop.

Windows on AWS EC2: Install software with Chocolatey package manager

Why

When you create a new EC2 instance, you usually would like to install some software on top of the OS during the creation process. But unlike Linux, Windows doesn't come a package manager like yum or apt. Chocolatey is such a package manager that can either be used for free with community-made packages or as an enterprise solution with a custom repository.

How

To install and manage software automatically on instance launch, paste the code below into the UserData field. This will install Chocolatey package manager first. Then you can install software packages from Chocolatey's community repository as shown below via choco install -y <package-name>.

Setting it up

The example script UserData.ps1 below will install Chocolatey along with the AWS CLI (v2) and PuTTY. Use it directly for the "User Data" field while creating a new instance or paste its contents into a PowerShell window that runs under an administrative account.

Troubleshooting

On Windows Server 2019, check C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log. Paths on other Windows releases may differ, check our article: https://aws.amazon.com/premiumsupport/knowledge-center/ec2-windows-troubleshoot-user-data/

Room for improvement

  • Use persistent UserData to automatically update all packages (cup all)
  • Install from self-hosted repository (paid option)
  • Install more packages (see "more-packages.ps1" below for some suggestions)
# A totally biased and subjective list of my favourite packages
# DBeaver: Multi-database client
choco install -y dbeaver
# pgadmin4: PostgreSQL admin GUI
choco install -y pgadmin4
# Git
choco install -y git.install
# ConEmu: fast and reliable terminal window
choco install -y conemu
# Brave: A browser that lets you browse safer and faster by blocking ads and trackers.
choco install -y brave
# Chromium: "Chrome without Google"
choco install -y chromium
# Notepad++
choco install -y notepadplusplus.install
# CloudBerry Explorer: Access S3 Buckets Explorer-style (requires registration!)
choco install -y cloudberryexplorer.s3
# MobaXterm Home Edition. Ultimate toolbox for remote computing
choco install -y mobaxterm
# Python 3
choco install -y python3
# A libre FTP, SFTP, WebDAV, S3, Backblaze B2, Azure & OpenStack Swift browser.
choco install -y cyberduck
# Or stick to the good ol' WinSCP
choco install -y winscp.install
# 7-Zip archive manager
choco install -y 7zip.install
# Desktop Version of popular diagrams.net diagramming software
choco install -y drawio
<powershell>
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
choco install -y awscli
choco install -y putty.install
</powershell>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment