Packer with AWS EC2Launch

Hello,
Does anyone know if it is possible to use the EC2Launch V2 Format with the user-data-file property instead of a powershell script? It would be nice to be able to leverage the more declarative syntax than having to script it in powershell.

The following provisioner declaration worked for me for EC2Launch v2 on a Windows Server 2022 AMI:

  provisioner "powershell" {
    inline = [
      "& 'C:/Program Files/Amazon/EC2Launch/ec2launch' reset --block",
      "& 'C:/Program Files/Amazon/EC2Launch/ec2launch' sysprep --shutdown --block",
    ]
  }

You can also customise agent-config.yml (located at C:/ProgramData/Amazon/EC2Launch/config.agent-config.yml), for example to add a runScript task to invoke some custom code (separate from regular user data). You would typically use a templatefile provisioner to place the config file inside your AMI.

The default agent-config.yml looks like this:

version: 1.0
config:
  - stage: boot
    tasks:
      - task: extendRootPartition
  - stage: preReady
    tasks:
      - task: activateWindows
        inputs:
          activation:
            type: amazon
      - task: setDnsSuffix
        inputs:
          suffixes:
            - $REGION.ec2-utilities.amazonaws.com
      - task: setAdminAccount
        inputs:
          password:
            type: random
      - task: setWallpaper
        inputs:
          path: C:\ProgramData\Amazon\EC2Launch\wallpaper\Ec2Wallpaper.jpg
          attributes:
            - hostName
            - instanceId
            - privateIpAddress
            - publicIpAddress
            - instanceSize
            - availabilityZone
            - architecture
            - memory
            - network
  - stage: postReady
    tasks:
      - task: startSsm
1 Like