Skip to content

Instantly share code, notes, and snippets.

@lukeplausin
Last active October 22, 2025 04:14
Show Gist options
  • Save lukeplausin/4b412d83fb1246b0bed6507b5083b3a7 to your computer and use it in GitHub Desktop.
Save lukeplausin/4b412d83fb1246b0bed6507b5083b3a7 to your computer and use it in GitHub Desktop.

Revisions

  1. lukeplausin revised this gist Sep 14, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion transfer_ssm_file.sh
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,6 @@ cd && sudo yum install nc -y && sudo nc -l -p 1234 > the_file.tar.gz
    aws ssm start-session --target $INSTANCE_ID --document-name AWS-StartPortForwardingSession --parameters '{"portNumber":["1234"],"localPortNumber":["1234"]}'

    # Step 3: On yet another shell, cat the source file into the transfer port on localhost over the tunnel
    nc -w 3 127.0.0.1 1234 < kidsloop-migrate.tar.gz
    nc -w 3 127.0.0.1 1234 < the_file.tar.gz

    # Step 4: Once the command in step 3 finishes, close all of the other shell sessions. Your file should be on the target now.
  2. lukeplausin created this gist Aug 20, 2021.
    21 changes: 21 additions & 0 deletions transfer_ssm_file.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # This script will explain how to transfer a file to EC2 using SSM ONLY!

    # You will need to have permission to run SSM commands on the target machine and have sudo access as well

    # Infos
    INSTANCE_ID=i-1234567890
    FILE_NAME=the_file.tar.gz

    # Step 1: Run command on machine to install netcat and dump from port to filename
    # < Start session
    aws ssm start-session --target $INSTANCE_ID --document-name
    # < (On target machine) :
    cd && sudo yum install nc -y && sudo nc -l -p 1234 > the_file.tar.gz

    # Step 2: On another shell, open a port-forwarding session from your machine to the target machine
    aws ssm start-session --target $INSTANCE_ID --document-name AWS-StartPortForwardingSession --parameters '{"portNumber":["1234"],"localPortNumber":["1234"]}'

    # Step 3: On yet another shell, cat the source file into the transfer port on localhost over the tunnel
    nc -w 3 127.0.0.1 1234 < kidsloop-migrate.tar.gz

    # Step 4: Once the command in step 3 finishes, close all of the other shell sessions. Your file should be on the target now.