Skip to content

Creating AWS S3 Bucket

Before creating resources, you need to configure AWS credentials for Terraform to authenticate with AWS APIs.

  1. AWS CLI Configuration: aws configure
  2. Environment Variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  3. IAM Roles: For EC2 instances or AWS services
  4. AWS Profiles: Named credential profiles

Object storage service that offers scalability, data availability, security, and performance.

  1. Create AWS Account: Sign up for AWS free tier if you don’t have an account
  2. Install AWS CLI: Download and install from AWS official website
  3. Configure Credentials: Set up your AWS access keys

Check your system architecture first:

Terminal window
# Linux/macOS
uname -m
# Windows PowerShell
$env:PROCESSOR_ARCHITECTURE

Official Website: https://aws.amazon.com/cli/

Windows:

Terminal window
# Using MSI installer (recommended)
# Download from: <https://awscli.amazonaws.com/AWSCLIV2.msi>
# Using winget
winget install Amazon.AWSCLI
# Using chocolatey
choco install awscli

macOS:

Terminal window
# Using official installer
curl "<https://awscli.amazonaws.com/AWSCLIV2.pkg>" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
# Using Homebrew
brew install awscli

Ubuntu/Debian:

Terminal window
# Update package index
sudo apt update
# Install AWS CLI v2 (choose based on your architecture)
# For x86_64
curl "<https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip>" -o "awscliv2.zip"
# For ARM64
curl "<https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip>" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Verify installation
aws --version
Terminal window
aws configure

Enter your:

  • AWS Access Key ID
  • AWS Secret Access Key
  • Default region (e.g., us-east-1)
  • Default output format (json)
Terminal window
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_DEFAULT_REGION="us-east-1"
  1. Get familiar with Terraform AWS documentation
  2. Create AWS resources using terraform
    • S3 bucket with unique name
  3. Practice Terraform commands
    • Initialize the working directory
    • Plan the infrastructure changes
    • Apply the configuration
    • Verify resources in AWS Console
  • Resource Names: S3 bucket names must be globally unique
  • Regions: Ensure you’re working in your intended AWS region
  • Costs: Monitor AWS costs, even in free tier
  • Cleanup: Always destroy resources when done practicing
Terminal window
# Initialize Terraform
terraform init
# Validate configuration
terraform validate
# Plan changes
terraform plan
# Apply changes
terraform apply
# Show current state
terraform show
# Destroy resources
terraform destroy
  • Check AWS credentials are properly configured
  • Verify region settings match your intended deployment location
  • Ensure S3 bucket names are unique and follow naming conventions
  • Review AWS CloudTrail for API call logs if needed
Terminal window
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
}
}
provider "aws" {
# Configuration options
region = "us-east-1"
}
# Create a S3 bucket
resource "aws_s3_bucket" "tf_test_baivab_bucket" {
bucket = "my-tf-test-baiv-bucket-101"
tags = {
Name = "My bucket"
Environment = "Dev"
}
}