This Node.js application automates the setup of AWS S3 buckets, replication, IAM users, and SNS notifications for the Sealed Love project.
- Creates IAM users with appropriate permissions
- Sets up S3 buckets in all AWS regions with consistent naming
- Configures replication from regional buckets to a central bucket
- Creates SNS topics with HTTPS subscriptions for notifications
- Supports the required bucket structure:
/stories/{env}/{UUID}/
- Node.js (v14 or higher)
- AWS account with administrative access
- AWS credentials configured locally
- AWS SDK v3 (installed via npm)
- Clone this repository
- Run
npm installto install dependencies - Create a
.envfile with your AWS credentials (see.env.example)
You can run the setup using npm scripts or directly with Node.js:
# Run the complete setup
npm start
# Run specific parts of the setup
npm run users # Only create IAM users
npm run buckets # Only create S3 buckets
npm run sns # Only create SNS topics and subscriptions
npm run replication # Only configure bucket replication
# Clean up all resources created by this script
npm run cleanup# Run the complete setup
node index.js
# Run specific parts of the setup
node index.js --users-only
node index.js --buckets-only
node index.js --sns-only
node index.js --replication-only
# Clean up all resources created by this script
node index.js --cleanupEdit the config.js file to customize:
- Target AWS regions
- Bucket naming
- SNS endpoints
- IAM user names and policies
This project uses AWS SDK v3, which offers several advantages over v2:
- Modular architecture: Only import the services you need
- Reduced bundle size
- Improved TypeScript support
- Command-based API design
Example of AWS SDK v3 usage in this project:
// Creating an S3 bucket with AWS SDK v3
const { S3Client, CreateBucketCommand } = require('@aws-sdk/client-s3');
const s3Client = new S3Client({ region });
const params = { Bucket: bucketName };
// Special handling for us-east-1 region
if (region !== 'us-east-1') {
params.CreateBucketConfiguration = { LocationConstraint: region };
}
await s3Client.send(new CreateBucketCommand(params));To remove all AWS resources created by this script, run:
npm run cleanupThis will delete resources in the following order:
- Remove S3 event notifications from buckets
- Delete SNS topics and subscriptions
- Delete S3 buckets (including emptying all objects and versions)
- Delete IAM users, their access keys, and attached policies
- Delete IAM roles used for replication
- The created IAM users will have access keys generated
- Save the access keys securely as they will only be shown once
- The IAM users have the minimum permissions required for their roles