Created
February 20, 2025 06:29
-
-
Save camallen/ac7419a5cefb1a4b039e5d9edc5a3f11 to your computer and use it in GitHub Desktop.
Edit S3 remote file and upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
SUM=$(which sha512sum || which sha || which md5sum || which md5 || true) | |
# modify the following to match the s3 setup you desire | |
path="s3://bucket_name/path/$1" | |
tempfile=$(mktemp ~/.tmpXXXXXX) | |
trap "rm -f $tempfile" INT TERM HUP EXIT | |
aws s3 cp $path $tempfile | |
if [ ! -z "$SUM" ] | |
then | |
FILEHASH=$($SUM $tempfile) | |
fi | |
"${EDITOR:-vim}" $tempfile | |
if [ -z "$FILEHASH" ] || [ "$FILEHASH" != "$($SUM $tempfile)" ] | |
then | |
aws s3 cp --sse aws:kms $tempfile $path | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Claude AI improvements
I'll help modify the script to work better with VSCode while maintaining the security aspects. Here's an improved version:
Key improvements made:
Uses VSCode's wait flag (
-w
): This makes the script wait until you close the file in VSCode before continuingBetter file organization:
Added error handling:
Better user feedback:
Configuration section at the top:
To use this script:
s3edit.sh
chmod +x s3edit.sh
./s3edit.sh myfile.json
You can also set up a VSCode keybinding for this script by adding to your
keybindings.json
:One additional improvement you might consider is adding a file extension whitelist or specific S3 path restrictions for security. Let me know if you'd like me to add those or explain any part in more detail!