
{"id":103,"date":"2025-06-10T21:51:10","date_gmt":"2025-06-10T20:51:10","guid":{"rendered":"https:\/\/blog.mkcloudai.com\/?p=103"},"modified":"2025-06-10T21:51:10","modified_gmt":"2025-06-10T20:51:10","slug":"step-by-step-guide-to-create-a-s3-bucket-and-upload-a-file-and-put-permission-using-aws-cli","status":"publish","type":"post","link":"https:\/\/blog.mkcloudai.com\/?p=103","title":{"rendered":"Step-by-step guide to create a s3 bucket and upload a file and put permission using aws cli"},"content":{"rendered":"\n<p>Here\u2019s a full step-by-step guide to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create an IAM user in AWS<\/strong><\/li>\n\n\n\n<li><strong>Set up AWS CLI on a Windows computer<\/strong><\/li>\n\n\n\n<li><strong>Create a Python virtual environment and install boto3<\/strong><\/li>\n\n\n\n<li><strong>Create an S3 bucket<\/strong><\/li>\n\n\n\n<li><strong>Upload a file<\/strong><\/li>\n\n\n\n<li><strong>Set permissions using AWS CLI<\/strong><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83e\uddd1\u200d\ud83d\udcbb Step 1: Create an IAM User (from AWS Console)<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to the <a class=\"\" href=\"https:\/\/console.aws.amazon.com\/iam\/\">IAM Console<\/a><\/li>\n\n\n\n<li>Click <strong>Users<\/strong> > <strong>Add users<\/strong><\/li>\n\n\n\n<li>Set <strong>User name<\/strong>: e.g., <code>aws-cli-user<\/code><\/li>\n\n\n\n<li>Check <strong>Programmatic access<\/strong><\/li>\n\n\n\n<li>Click <strong>Next: Permissions<\/strong><\/li>\n\n\n\n<li>Attach policies:\n<ul class=\"wp-block-list\">\n<li>Choose <strong>Attach existing policies directly<\/strong><\/li>\n\n\n\n<li>Select <code>AmazonS3FullAccess<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Click <strong>Next<\/strong> > <strong>Create user<\/strong><\/li>\n\n\n\n<li>Download or copy:\n<ul class=\"wp-block-list\">\n<li><strong>Access key ID<\/strong><\/li>\n\n\n\n<li><strong>Secret access key<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2699\ufe0f Step 2: Install and Configure AWS CLI on Windows<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Download AWS CLI<\/strong> from: <a class=\"\" href=\"https:\/\/aws.amazon.com\/cli\/\">https:\/\/aws.amazon.com\/cli\/<\/a><\/li>\n\n\n\n<li>Install it and open <strong>Command Prompt<\/strong><\/li>\n\n\n\n<li>Run: bashCopyEdit<code>aws configure<\/code><\/li>\n\n\n\n<li>Enter the credentials from IAM:\n<ul class=\"wp-block-list\">\n<li>AWS Access Key ID<\/li>\n\n\n\n<li>AWS Secret Access Key<\/li>\n\n\n\n<li>Region (e.g., <code>us-east-1<\/code>)<\/li>\n\n\n\n<li>Output format (e.g., <code>json<\/code>)<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udc0d Step 3: Create Python Virtual Environment &amp; Install boto3<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open <strong>Command Prompt<\/strong> in your project directory.<\/li>\n\n\n\n<li>Run: bashCopyEdit<code>python -m venv venv .\\venv\\Scripts\\activate pip install boto3<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2601\ufe0f Step 4: Create an S3 Bucket Using AWS CLI<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>S3 bucket names must be globally unique.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>aws s3api create-bucket --bucket my-unique-bucket-name-123 --region us-east-1<br><\/code><\/pre>\n\n\n\n<p>For other regions:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>aws s3api create-bucket --bucket my-unique-bucket-name-123 --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2<br><\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcc1 Step 5: Upload a File to the S3 Bucket<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>aws s3 cp myfile.txt s3:\/\/my-unique-bucket-name-123\/<br><\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd10 Step 6: Set Permissions (Make Public or Set Bucket Policy)<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Option 1: Make the object public<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>aws s3api put-object-acl --bucket my-unique-bucket-name-123 --key myfile.txt --acl public-read<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Option 2: Add a bucket policy (e.g., allow public read to all files in the bucket)<\/h4>\n\n\n\n<p>Create a file <code>bucket-policy.json<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">jsonCopyEdit<code>{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Sid\": \"PublicReadGetObject\",\n      \"Effect\": \"Allow\",\n      \"Principal\": \"*\",\n      \"Action\": \"s3:GetObject\",\n      \"Resource\": \"arn:aws:s3:::my-unique-bucket-name-123\/*\"\n    }\n  ]\n}\n<\/code><\/pre>\n\n\n\n<p>Apply it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>aws s3api put-bucket-policy --bucket my-unique-bucket-name-123 --policy file:\/\/bucket-policy.json<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here\u2019s a full step-by-step guide to: \ud83e\uddd1\u200d\ud83d\udcbb Step 1: Create an IAM User (from AWS Console) \u2699\ufe0f Step 2: Install [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5,6,9],"tags":[11,54,13],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-aws","category-s3","category-tutorial","tag-amazon-s3","tag-aws-cli","tag-aws-s3"],"_links":{"self":[{"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=103"}],"version-history":[{"count":1,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions\/104"}],"wp:attachment":[{"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}