hashicorp / hashicorp/packer-plugin-amazon

SSH time out due to AWS Session Manager tunnel failure

Open
#30 0 comments 0 reactions 0 assignees View on GitHub
builder/amazon question
Dominant language
Go
Stars
91
Forks
141
Avg merge
2d 18h
Merged PRs (30d)
3

Description

_This issue was originally opened by @Venkat1505 as hashicorp/packer#10508. It was migrated here as a result of the [Packer plugin split](https://github.com/hashicorp/packer/issues/8610#issuecomment-770034737). The original body of the issue is below._


I am using the AWS Codebuild with packer for creating golden-ami. I am using the session_manager in packer to connect AWS.

I am getting the below error?

Can you please help?

Buildspec.yml

```yaml
version: 0.2

phases:
install:
commands:
- echo Executing install phases
- curl -o packer.zip https://releases.hashicorp.com/packer/1.6.6/packer_1.6.6_linux_amd64.zip && unzip packer.zip
- ./packer version
- curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/linux_64bit/session-manager-plugin.rpm" -o
- "session-manager-plugin.rpm"
- yum install -y session-manager-plugin.rpm
- session-manager-plugin

pre_build:
commands:

- ./packer validate packer_cis.json

build:
commands:


- PACKER_LOG=1 ./packer build -debug -color=false packer_cis.json | tee build.log
- cat packerlog.txt

post_build:
commands:
- egrep "${AWS_REGION}\:\sami\-" build.log | cut -d' ' -f2 > ami_id.txt
# Packer doesn't return non-zero status; we must do that if Packer build failed
- test -s ami_id.txt || exit 1
- sed -i.bak "s/<>/$(cat ami_id.txt)/g" ami_builder_event.json
- aws events put-events --entries file://ami_builder_event.json

artifacts:
files:
- ami_builder_event.json
- build.log
discard-paths: yes

```

```json
{
"variables": {
"aws_access_key": "******K",
"aws_secret_key": "*******a",
"vpc": "{{env `BUILD_VPC_ID`}}",
"subnet": "******",
"aws_region": "{{env `AWS_REGION`}}"
},
"builders": [{
"name": "AWS AMI Builder - CIS",
"type": "amazon-ebs",
"region": "{{user `aws_region`}}",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "amzn-ami-hvm-2018.03.0.20200318.1-x86_64-ebs",
"root-device-type": "ebs"
},
"owners": ["1111111111","
],
"most_recent": true
},
"instance_type": "t2.micro",
"ami_name": "Prod-CIS-Latest-AMZN-{{isotime \"02-Jan-06 03_04_05\"}}",
"ami_description": "Amazon Linux CIS with Cloudwatch Logs agent",
"associate_public_ip_address": "true",
"vpc_id": "*********",
"subnet_id": "***************",
"security_group_id": "****************",
"iam_instance_profile": "AmazonEC2RoleforSSM",
"communicator": "ssh",
"ssh_username": "ec2-user",
"ssh_interface": "session_manager"

}],
"provisioners": [{
"type": "shell",
"inline": [
"sudo pip install ansible==2.7.9"
]
},
{
"type": "ansible-local",
"playbook_file": "ansible/playbook.yaml",
"role_paths": [
"ansible/roles/common"
],
"playbook_dir": "ansible",
"galaxy_file": "ansible/requirements.yaml"
},

{
"type": "shell",
"inline": [
"rm .ssh/authorized_keys ; sudo rm /root/.ssh/authorized_keys"
]
}
]
}
```

```txt
==> AWS AMI Builder - CIS: Launching a source AWS instance...
--
219 | ==> AWS AMI Builder - CIS: Adding tags to source instance
220 | AWS AMI Builder - CIS: Adding tag: "Name": "Packer Builder"
221 | AWS AMI Builder - CIS: Instance ID: i-00dd9fdfd466d5bfa462f
222 | ==> AWS AMI Builder - CIS: Waiting for instance (i-00dd9fdfd466d5bfa462f) to become ready...
223 | AWS AMI Builder - CIS: Public DNS: ec2-54-259-25-54.compute-1.amazonaws.com
224 | AWS AMI Builder - CIS: Public IP: 54.259.25.54
225 | AWS AMI Builder - CIS: Private IP: 10.113.17.203
226 | 2021/01/21 23:18:10 packer-builder-amazon-ebs plugin: Error asking for input: no available tty
227 | 2021/01/21 23:18:10 packer-builder-amazon-ebs plugin: [INFO] Not using winrm communicator, skipping get password...
228 | 2021/01/21 23:18:10 packer-builder-amazon-ebs plugin: Error asking for input: no available tty
229 | 2021/01/21 23:18:10 packer-builder-amazon-ebs plugin: Found available port: 8372 on IP: 0.0.0.0
230 | 2021/01/21 23:18:10 packer-builder-amazon-ebs plugin: ssm: Starting PortForwarding session to instance i-00dd9466d5bfa462f
231 | ==> AWS AMI Builder - CIS: Using ssh communicator to connect: localhost
232 | 2021/01/21 23:18:10 packer-builder-amazon-ebs plugin: Error asking for input: no available tty
233 | 2021/01/21 23:18:10 packer-builder-amazon-ebs plugin: [INFO] Waiting for SSH, up to timeout: 1h0m0s
234 | ==> AWS AMI Builder - CIS: Waiting for SSH to become available...
235 | 2021/01/21 23:18:10 packer-builder-amazon-ebs plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:8372: connect: connection refused
236 | 2021/01/21 23:18:11 packer-builder-amazon-ebs plugin: Retryable error: TargetNotConnected: i-00dd9fdfd466d5bfa462f is not connected.
237 | 2021/01/21 23:18:11 packer-builder-amazon-ebs plugin: Retryable error: TargetNotConnected: i-00dd9fdfd466d5bfa462f is not connected.
238 | 2021/01/21 23:18:11 packer-builder-amazon-ebs plugin: Retryable error: TargetNotConnected: i-00dd9fdfd466d5bfa462f is not connected.
239 | 2021/01/21 23:18:12 packer-builder-amazon-ebs plugin: Retryable error: TargetNotConnected: i-00dd9fdfd466d5bfa462f is not connected.
240 | 2021/01/21 23:18:14 packer-builder-amazon-ebs plugin: Retryable error: TargetNotConnected: i-00dd9fdfd466d5bfa462f is not connected.
241 | 2021/01/21 23:18:15 packer-builder-amazon-ebs plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:8372: connect: connection refused
242 | 2021/01/21 23:18:17 packer-builder-amazon-ebs plugin: Retryable error: TargetNotConnected: i-00dd9fdfd466d5bfa462f is not connected.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.