transfer files to ec2 instances via SSM and netcat

06 Feb 2024

Step 1. Run netcat on the target EC2 machine via SSM

$ aws ssm start-session --target $INSTANCE_ID --document-name
ssm $ nc -l -p 9999 > $FILE_NAME

Step 2. In another shell open a port-forwarding session:

$ aws ssm start-session --target $INSTANCE_ID --document-name AWS-StartPortForwardingSession --parameters '{"portNumber":["9999"],"localPortNumber":["9999"]}'

Step 3. In a 3rd shell transfer the file via netcat:

$ nc -w 3 9999 < $FILE_NAME