Guide for working with AWS S3 buckets, objects, policies, lifecycle rules, and storage classes using AWS CLI and best practices
This skill guides you through working with Amazon S3 (Simple Storage Service), AWS's industry-leading object storage service. Use this to manage buckets, objects, access policies, lifecycle rules, and storage classes.
Helps you perform common AWS S3 operations including:
Before starting, ensure AWS CLI is installed and configured with proper credentials:
```bash
aws --version
aws sts get-caller-identity
```
If not configured, run `aws configure` and provide your access key, secret key, region, and output format.
Create a new S3 bucket in your desired region:
```bash
aws s3api create-bucket --bucket YOUR_BUCKET_NAME --region YOUR_REGION --create-bucket-configuration LocationConstraint=YOUR_REGION
```
**Important:** Bucket names must be globally unique across all AWS accounts. Use lowercase letters, numbers, and hyphens only.
Upload files to your bucket:
```bash
aws s3 cp /path/to/local/file.txt s3://YOUR_BUCKET_NAME/
aws s3 cp /path/to/local/directory s3://YOUR_BUCKET_NAME/directory/ --recursive
aws s3 cp file.txt s3://YOUR_BUCKET_NAME/ --metadata key1=value1,key2=value2
```
View and manage objects in your bucket:
```bash
aws s3 ls s3://YOUR_BUCKET_NAME/
aws s3 ls s3://YOUR_BUCKET_NAME/directory/
aws s3 cp s3://YOUR_BUCKET_NAME/file.txt /local/path/
aws s3 rm s3://YOUR_BUCKET_NAME/file.txt
```
Set bucket policies to control access:
```bash
cat > policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}
EOF
aws s3api put-bucket-policy --bucket YOUR_BUCKET_NAME --policy file://policy.json
```
Enable versioning to keep multiple versions of objects:
```bash
aws s3api put-bucket-versioning --bucket YOUR_BUCKET_NAME --versioning-configuration Status=Enabled
aws s3api get-bucket-versioning --bucket YOUR_BUCKET_NAME
```
Set up lifecycle policies to automatically transition objects between storage classes or delete them:
```bash
cat > lifecycle.json <<EOF
{
"Rules": [
{
"Id": "MoveToGlacierAfter90Days",
"Status": "Enabled",
"Transitions": [
{
"Days": 90,
"StorageClass": "GLACIER"
}
],
"Expiration": {
"Days": 365
},
"Filter": {
"Prefix": "logs/"
}
}
]
}
EOF
aws s3api put-bucket-lifecycle-configuration --bucket YOUR_BUCKET_NAME --lifecycle-configuration file://lifecycle.json
```
Track requests to your bucket:
```bash
aws s3api create-bucket --bucket YOUR_BUCKET_NAME-logs --region YOUR_REGION
aws s3api put-bucket-logging --bucket YOUR_BUCKET_NAME --bucket-logging-status file://logging.json
```
Choose appropriate storage classes based on access patterns:
Upload with specific storage class:
```bash
aws s3 cp file.txt s3://YOUR_BUCKET_NAME/ --storage-class STANDARD_IA
```
Trigger workflows when objects are created or deleted:
```bash
aws s3api put-bucket-notification-configuration --bucket YOUR_BUCKET_NAME --notification-configuration file://notification.json
```
Encrypt objects at rest:
```bash
aws s3api put-bucket-encryption --bucket YOUR_BUCKET_NAME --server-side-encryption-configuration '{
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}
]
}'
```
Set up CloudWatch metrics for monitoring:
```bash
aws s3api put-bucket-metrics-configuration --bucket YOUR_BUCKET_NAME --id EntireBucket --metrics-configuration '{
"Id": "EntireBucket",
"Filter": {
"Prefix": ""
}
}'
```
```bash
aws s3 website s3://YOUR_BUCKET_NAME/ --index-document index.html --error-document error.html
```
Configure replication rules to copy objects to another region for disaster recovery or compliance.
Use S3 as centralized repository for structured and unstructured data with S3 Select for querying.
Implement lifecycle policies to transition backups to Glacier for cost-effective long-term storage.
1. **Block Public Access**: Enable S3 Block Public Access settings by default
2. **Use IAM Policies**: Grant least-privilege access using IAM roles and policies
3. **Enable MFA Delete**: Require multi-factor authentication for object deletion
4. **Encrypt Data**: Use server-side encryption (SSE-S3, SSE-KMS) or client-side encryption
5. **Enable Logging**: Track access requests with server access logging or CloudTrail
6. **Versioning**: Enable versioning to protect against accidental deletions
**Access Denied Errors**: Check bucket policies, IAM permissions, and Block Public Access settings.
**Slow Upload/Download**: Use multipart upload for large files, check network bandwidth, consider S3 Transfer Acceleration.
**High Costs**: Review storage class usage, enable lifecycle policies, check for incomplete multipart uploads.
For detailed information, refer to the official AWS S3 documentation:
https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/aws-s3-bucket-and-object-management/raw