Skip to content

Instantly share code, notes, and snippets.

@stefan-matic
Created November 14, 2019 08:47
Show Gist options
  • Save stefan-matic/50904258e7c3e29156c1b7a3ec403deb to your computer and use it in GitHub Desktop.
Save stefan-matic/50904258e7c3e29156c1b7a3ec403deb to your computer and use it in GitHub Desktop.
Allows uploading to S3 using AWS CLI. Create folder "s3-upload" on your C:\ (root), and inside create the folder "files". Place the bat inside "s3-upload"
@echo off
color 02
SETLOCAL EnableDelayedExpansion
set s3-folder=C:\s3-upload
set test=specific-test-folder/
set demo=specific-demo-folder/
set prod=specific-production-folder/
set test-link=https://bucket-name.s3.eu-central-1.amazonaws.com/Path/To/S3/Folder
set demo-link=https://bucket-name.s3.eu-central-1.amazonaws.com/Path/To/S3/Folder
set prod-link=https://bucket-name.s3.eu-central-1.amazonaws.com/Path/To/S3/Folder
set s3bucketpath=s3://bucket-name/Path/
:: Get data and time.
for /f "skip=1" %%d in ('wmic OS GET LocalDateTime') do (set ldt=%%d & goto PARSELDT)
:PARSELDT
set date=%ldt:~0,8%_%ldt:~8,4%
CLS
echo 1 = Test
echo 2 = Demo
echo 3 = Production
CHOICE /C 123 /M "Where to upload?"
:: Note - list ERRORLEVELS in decreasing order
IF ERRORLEVEL 3 GOTO Production
IF ERRORLEVEL 2 GOTO Demo
IF ERRORLEVEL 1 GOTO Test
:Test
aws s3 cp %s3-folder%\files\ %s3bucketpath%/%test% --recursive --acl public-read
dir /b /a-d %s3-folder%\files > %s3-folder%\files.txt
for /f "tokens=* delims= " %%a in (%s3-folder%\files.txt) do (
set /a N+=1
echo ^%test-link%/%%a^ >>%s3-folder%\links-%date%.txt
)
GOTO End
:Demo
aws s3 cp %s3-folder%\files\ %s3bucketpath%/%demo% --recursive --acl public-read
dir /b /a-d %s3-folder%\files > %s3-folder%\files.txt
for /f "tokens=* delims= " %%a in (%s3-folder%\files.txt) do (
set /a N+=1
echo ^%test-link%/%%a^ >>%s3-folder%\links-%date%.txt
)
GOTO End
:Production
aws s3 cp %s3-folder%\files\ %s3bucketpath%/%prod% --recursive --acl public-read
dir /b /a-d %s3-folder%\files > %s3-folder%\files.txt
for /f "tokens=* delims= " %%a in (%s3-folder%\files.txt) do (
set /a N+=1
echo ^%prod-link%/%%a^ >>%s3-folder%\links-%date%.txt
)
GOTO End
:End
%s3-folder%\links-%date%.txt
del /s /q %s3-folder%\files\*.*
del /s /q %s3-folder%\files.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment