Created
February 28, 2024 03:25
-
-
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
This file contains 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
{ | |
"CORSRules": [ | |
{ | |
"AllowedOrigins": ["*"], | |
"AllowedHeaders": ["Authorization"], | |
"AllowedMethods": ["GET"], | |
"MaxAgeSeconds": 3000 | |
} | |
] | |
} |
This file contains 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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
)