[?1034hsh-4.2$ Cannot perform start session: EOF

Viewed 416

Getting below error while connecting aws ec2 instance through SSM in jenkins.

Starting session with SessionId: [?1034hsh-4.2$ Cannot perform start session: EOF

Command used in jenkins (execute shell): INSTANCE_ID=aws ec2 describe-instances --filters "Name=tag:t_name,Values=appdev" --region us-east-1 | jq -r .Reservations[].Instances[].InstanceId

echo "INSTANCE_ID: $INSTANCE_ID"

aws ssm start-session --region us-east-1 --target $INSTANCE_ID

1 Answers

Why do you want to start a session in Jenkins for SSM?

start-session is used to initiate a connection to a target (for example, a managed node) for a Session Manager session.

To work with SSM in Jenkins you can pass the commands directly without the need to create a session using send-command

Example: To untar files in your instance

aws ssm send-command --instance-ids "${INSTANCE_ID}" \
 --region us-east-1 --document-name "AWS-RunShellScript" \
 --output-s3-bucket-name "$bucketName" --output-s3-key-prefix "$bucketDir" \
 --comment "Untar Files" \
 --parameters '{"commands":["tar -xvf /tmp/repo.tar -C /tmp" ]}'

You can pass any number of commands using this way.

After each command, you can call a shell function to check the command status and if it fails you can exit your loop

Related