This repository contains a Packer template and supporting files for creating an AWS Windows AMI with OpenSSH. The code in this repository is inspired by this blog post and accompanying code.
This is an updated implementation of packer-aws-windows-ssh
with the following changes:
- The Packer template
aws-windows-ssh.pkr.hcl
is coded in HCL2 rather than JSON. - The image is based off Windows Server 2022
- OpenSSH is installed with
Add-WindowsCapability
per https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=powershell#install-openssh-for-windows - The code for downloading the ssh key is somewhat simplified and saves it to
$env:ProgramData\ssh\administrators_authorized_keys
- Sysprep is run via the newer EC2launch
- Chocolatey is installed for package management
- The template enables Fast Launch for the AMI (see
enable_fast_launch = true
)
In order to build this image you need an AWS account an access key. Once you have that you need to set the following environment variables:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
You can put this in your .zshrc
or .bashrc
file, for example:
# AWS packer config
export AWS_ACCESS_KEY_ID="<ACCESS_KEY>"
export AWS_SECRET_ACCESS_KEY="<AWS_SECRET_ACCESS_KEY>"
export AWS_DEFAULT_REGION="ca-central-1"
Once that's setup you'll need to initialize the template:
packer init .
Now build the image:
packer build aws-windows-ssh.pkr.hcl