Creating S3 Bucket with low level S3 API Command

The s3api is a command that allows users to interact with Amazon Simple Storage Service (S3) through the AWS CLI. With s3api, users can perform advanced operations on S3 buckets and objects such are configure bucket policies, set access control lists (ACLs), manage versioning, configure lifecycle policies, and more.

Creating bucket

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

  • create-bucket: This subcommand initiates the process of creating a new S3 bucket.
  • –bucket: This option is used to specify the name of the bucket you want to create.
  • –region: This option allows you to specify the AWS region where you want to create the bucket

Step 1: The command will create a s3 bucket with name gfg-eample3 in Europe (Ireland) region

aws s3api create-bucket --bucket gfg-example3 --region eu-west-1

Step 2: Attaching life cycle policy to bucket

aws s3api put-bucket-lifecycle-configuration –bucket <bucket-name> –lifecycle-configuration file://<lifecycle-config-file.json>

  • put-bucket-lifecycle-configuration: This is the subcommand used to set the lifecycle configuration for the specified bucket.
  • –bucket: This option specifies the name of the S3 bucket. s3 bucket should be present in s3.
  • –lifecycle-configuration: This option specifies the lifecycle configuration for the bucket.
  • First we will create json file which contains the life cycle rules for s3 bucket. Refer the document to know how to write life cycle policy for s3 bucket.
  • Then we will attach the Life cycle poliy to gfg-example3 bucket
aws s3api put-bucket-lifecycle-configuration --bucket gfg-example3 --lifecycle-configuration file://C:/Users/ravis/Desktop/life-cycle-policy.json

Life cycle policy

Life cycle attachment

Applying The ACL Property Of S3

Step 1: We can use the put-bucket-acl of s3api for specifying the ACL property of s3 bucket.

aws s3api put-bucket-acl –bucket <bucket-name> –acl <acl>

  • put-bucket-acl: This is the command used to set the access control list for the specified bucket.
  • –bucket: This option specifies the name of the S3 bucket
  • –acl: This option specifies the desired access control list for the bucket. The <acl> parameter can be set to one of the following values:
    • private: Bucket and objects are accessible only to the bucket owner.
    • public-read: Bucket is accessible to anyone, but object access is still controlled by individual object ACLs.
    • public-read-write: Bucket and objects are accessible to anyone. Use with caution.
aws s3api put-bucket-acl --bucket gfg-example3 --acl private

ACL policy

Step 2: Carefully review the bucket policies and IAM Policies in order to execute the commands properly.

How to Create AWS S3 Bucket using CLI ?

Amazon S3 is a Simple Storage Service in AWS that stores files of different types like Photos, Audio, and videos, as objects, providing more scalability and security. It allows users to store and retrieve any amount of data at any point in time from anywhere on the web. It facilitates features such as extremely high availability, security, and simple connections to other AWS Services. In this article, we will see how to create s3 buckets using AWS CLI

Similar Reads

Prerequisites

Introduction to s3 AWS CLI...

Creating S3 Bucket Using CLI

The AWS S3 command is part of the AWS Command Line Interface (CLI) and serves as a tool for interacting with Amazon Simple Storage Service (S3). The AWS s3 mb command creates a new bucket in Amazon S3. It’s a straightforward way to initiate the creation of a storage container within AWS. mb stands for make bucket The bucket name should be globally unique...

Uploading or Downloading Objects from S3 Bucket using AWS CLI Commands

The aws s3 cp command can be used for both uploading files to S3 bucket and downloading files from S3 bucket....

Creating S3 Bucket with low level S3 API Command

The s3api is a command that allows users to interact with Amazon Simple Storage Service (S3) through the AWS CLI. With s3api, users can perform advanced operations on S3 buckets and objects such are configure bucket policies, set access control lists (ACLs), manage versioning, configure lifecycle policies, and more....

Create AWS S3 Bucket Using CLI – FAQ’s

What is the use of an AWS S3 Bucket?...