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.
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>
.
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.
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/
- 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)