Skip to content

Windows Server 2022: The EC2Launcher must be reset at the end to allow building a custom AMI Windows image based on it with Packer #30

@tmak

Description

@tmak

I'm trying to build a custom AMI Windows image based on the runs-on Windows image, so that we can provision the necessary components to build our Unity applications with it.

The problem I'm running into is that the runs-on Windows image doesn't clean up EC2Launch setup at the end.
Due to that, if I try to build a new AMI image via Packer, my user script doesn't get executed.
I see the following in the EC2Launch agent.log on the Packer build instance:

...
2025-08-01 07:01:28 Info: Stage: postReady completed.
2025-08-01 07:01:28 Info: Run-once already exists: C:\ProgramData\Amazon\EC2Launch\state\.run-once
2025-08-01 07:01:28 Info: Replace C:\ProgramData\Amazon\EC2Launch\state\state.json with C:\ProgramData\Amazon\EC2Launch\state\previous-state.json
2025-08-01 07:01:28 Info: Success: C:\ProgramData\Amazon\EC2Launch\state\previous-state.json replaced C:\ProgramData\Amazon\EC2Launch\state\state.json
2025-08-01 07:01:28 Info: EC2Launch stopped
...

See Packer documentation reference for what should be added as a last provisioning step for Windows Server 2022 images: https://developer.hashicorp.com/packer/integrations/hashicorp/amazon/latest/components/builder/ebs#windows-2022-sysprep-commands-for-amazon-windows-amis-only

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions