AWS Code Build : Packer build finished in time out. Impossible to retrieve the ec2 password


I’m trying to build an ami with Packer via AWS Code Build. Unfortunately the build finished always by a timeout. The message is Build ‘xxxxxx-amibuilder’ errored after 21 minutes 21 seconds: Timeout waiting for password

Packer couldn’t retrieve the password. I’ve tried to launch manually a Ec2 from my golden ami and I was able to connect with a key-pair.

Below the code build logs:

==> altobasic-tenor-amibuilder: Prevalidating any provided VPC information
103 ==> altobasic-tenor-amibuilder: Prevalidating AMI Name: EUA-DV-TENOR-V1-ami-2021-10-10-21-21-35
104 altobasic-tenor-amibuilder: Found Image ID: ami-09a60634ac9249dfc
105 ==> altobasic-tenor-amibuilder: Creating temporary keypair: packer_61635ae1-f038-7b40-8e98-00c2e949e0e0
106 altobasic-tenor-amibuilder: Saving key for debug purposes: ec2_altobasic-tenor-amibuilder.pem
107 ==> altobasic-tenor-amibuilder: Launching a source AWS instance…
108 ==> altobasic-tenor-amibuilder: Adding tags to source instance
109 altobasic-tenor-amibuilder: Adding tag: “Name”: “packer-altobasic-tenor-ami-creation-ec2”
110 altobasic-tenor-amibuilder: Adding tag: “Author”: “Packer”
111 altobasic-tenor-amibuilder: Instance ID: i-0ebf260ed7fd8ee4b
112 ==> altobasic-tenor-amibuilder: Waiting for instance (i-0ebf260ed7fd8ee4b) to become ready…
113 altobasic-tenor-amibuilder: Private IP:
114 ==> altobasic-tenor-amibuilder: Waiting for auto-generated password for instance…
115 altobasic-tenor-amibuilder: It is normal for this process to take up to 15 minutes,
116 altobasic-tenor-amibuilder: but it usually takes around 5. Please wait.
117 ==> altobasic-tenor-amibuilder: Timeout waiting for password.
118 ==> altobasic-tenor-amibuilder: Terminating the source AWS instance…
119 ==> altobasic-tenor-amibuilder: Cleaning up any extra volumes…
120 ==> altobasic-tenor-amibuilder: Destroying volume (vol-06ba3dd3349b4a84c)…
121 ==> altobasic-tenor-amibuilder: Destroying volume (vol-017e57b51f141c4a2)…
122 ==> altobasic-tenor-amibuilder: Deleting temporary keypair…
123 Build ‘altobasic-tenor-amibuilder’ errored after 21 minutes 21 seconds: Timeout waiting for password.

Any insight?