Skip to content

Instantly share code, notes, and snippets.

@mhornbacher
Created February 28, 2024 03:25
Show Gist options
  • Save mhornbacher/3973f7bac2e6c8fd24b8c9aa06b28b0c to your computer and use it in GitHub Desktop.
Save mhornbacher/3973f7bac2e6c8fd24b8c9aa06b28b0c to your computer and use it in GitHub Desktop.
Update a Bucketer bucket in Heroku to allow CORS GET requests from any domain via Bash Script
{
"CORSRules": [
{
"AllowedOrigins": ["*"],
"AllowedHeaders": ["Authorization"],
"AllowedMethods": ["GET"],
"MaxAgeSeconds": 3000
}
]
}
#!/bin/bash
# Check if AWS CLI is installed
if ! command -v aws &> /dev/null; then
echo "AWS CLI is not installed. Proceeding with installation..."
# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Verify installation
if command -v aws &> /dev/null; then
echo "AWS CLI has been installed successfully."
else
echo "Failed to install AWS CLI. Please install it manually."
exit 1
fi
else
echo "AWS CLI is already installed."
fi
# Update AWS Credentials locally
echo "Signing into AWS"
export AWS_ACCESS_KEY_ID="$(heroku config:get BUCKETEER_AWS_ACCESS_KEY_ID)"
export AWS_SECRET_ACCESS_KEY="$(heroku config:get BUCKETEER_AWS_SECRET_ACCESS_KEY)"
export AWS_DEFAULT_REGION="$(heroku config:get BUCKETEER_AWS_REGION)"
# Update CORS Settings
aws s3api put-bucket-cors --bucket "$(heroku config:get BUCKETEER_BUCKET_NAME)" --cors-configuration file://cors.json
@mhornbacher
Copy link
Author

mhornbacher commented Feb 28, 2024

To install put both these files in your heroku project (anywhere is fine) and run chmod +x s3_cors_bucketer.sh

To update/run run the script (./s3_cors_bucketer.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment