recent

Titulo

AWS CLI -S3 Commands

Let's explore some common Amazon S3 commands using the AWS CLI. These commands allow you to manage S3 buckets and objects effectively. Remember that you'll need to have the AWS CLI installed and configured with appropriate permissions. Here are some examples:

1. **Copying Files:**

   - To copy files between local storage and S3:

     aws s3 cp <source> <destination>

2. **Moving Files:**

   - To move files (rename or move between local and S3):

     aws s3 mv <source> <destination>

3. **Removing Files:**

   - To delete files from S3:

     aws s3 rm <s3://bucket-name/object-key>

4. **Creating Buckets:**

   - To create an S3 bucket:

     aws s3api create-bucket --bucket <bucket-name> --region <region>

5. **Listing Objects:**

   - To list objects in an S3 bucket:

     aws s3 ls s3://<bucket-name>

6. **Syncing Folders:**

   - To sync local folders with S3 (upload/download changes):

     aws s3 sync <local-path> s3://<bucket-name>

7. **Bucket Configuration:**

   - To configure bucket properties (e.g., versioning, logging, CORS):

     aws s3api put-bucket-versioning --bucket <bucket-name> --versioning-configuration Status=Enabled

8. **Object Metadata:**

   - To set metadata for an object:

     aws s3api copy-object --copy-source <source> --bucket <bucket-name> --key <object-key> --metadata-directive REPLACE --metadata <key1=value1,key2=value2>

9. **Access Control:**

   - To grant public read access to an object:

     aws s3api put-object-acl --bucket <bucket-name> --key <object-key> --acl public-read

10. **Lifecycle Policies:**

    - To create a lifecycle policy for object expiration:

      aws s3api put-bucket-lifecycle-configuration --bucket <bucket-name> --lifecycle-configuration '{"Rules":[{"ID":"ExpireRule","Status":"Enabled","Prefix":"","Expiration":{"Days":30}}]}'

11. **Bucket Policy:**

    - To add a bucket policy allowing specific actions:

      aws s3api put-bucket-policy --bucket <bucket-name> --policy '{

        "Version": "2012-10-17",

        "Statement": [

          {

            "Effect": "Allow",

            "Principal": "*",

            "Action": ["s3:GetObject"],

            "Resource": "arn:aws:s3:::<bucket-name>/*"

          }

        ]

      }'

Remember to replace placeholders like `<bucket-name>`, `<source>`, and `<object-key>` with your actual values.

Interested in working with me? I can be reached at pbaniya04[at]gmail.com for any questions, consulting opportunities or you may drop a line to say HELLO. Thank your again for visiting my blog and looking forward to serving you more.

Have a Database-ious Day!

No comments

Powered by Blogger.