Yuri Slobodyanyuk Blog on Information Security 2024年09月12日
AWS cli cookbook
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了如何使用 AWS 命令行工具 (AWS CLI) 管理 Amazon S3 存储桶,涵盖了从创建存储桶、上传文件到删除存储桶等各种操作,并提供了详细的命令示例和解释。

😊 **创建和管理存储桶** - 使用 `awss3mbs3://testbucket` 命令在默认区域创建存储桶。 - 使用 `awss3mbs3://testbucket--regionus-east-1` 命令在指定区域创建存储桶。 - 使用 `awss3rbyurisk.info` 命令删除空存储桶。 - 使用 `awss3rbs3://yurisk.com--force` 命令强制删除非空存储桶,前提是存储桶中的对象未被版本化。 - 使用 `awss3rms3://yurisk.info--dryrun--rec` 命令模拟删除存储桶,不进行实际删除操作。 - 使用 `awss3rms3://yurisk.info--recursive` 命令递归删除存储桶中的所有内容,但不删除存储桶本身。 - 使用 `awss3rms3://yurisk.info--recursive--exclude"*.jpg"--exclude"*.png"` 命令递归删除存储桶中的所有文件,除了 JPEG 和 PNG 文件。 - 使用 `awss3rms3://yurisk.info--recursive--exclude"*"--include"*.jpg"` 命令仅删除存储桶中扩展名为 JPG 的文件。 - 使用 `awss3apidelete-bucket--bucketyurisk.info` 命令删除空存储桶。

😎 **列出存储桶内容** - 使用 `awss3ls` 命令列出用户帐户下的所有存储桶。 - 使用 `awss3lsyurisk.info--recursive` 命令递归列出指定存储桶 `yurisk.info` 中的所有内容。 - 使用 `awss3lsyurisk.com--recursive--human` 命令递归列出指定存储桶 `yurisk.com` 中的所有内容,并以易于理解的格式显示文件大小。 - 使用 `awss3lsyurisk.info--summarize--human--recursive` 命令列出指定存储桶 `yurisk.info` 中的所有内容,并显示对象数量和总大小的摘要信息。

😮 **设置和管理存储桶访问控制** - 使用 `awss3apiget-bucket-acl--bucketyurisk.info` 命令获取指定存储桶 `yurisk.info` 的访问控制列表 (ACL)。 - 使用 `awss3websites3://yurisk.info/--index-documentindex.html--error-documenterror.html` 命令配置存储桶 `yurisk.info` 以托管网站,并将默认的被服务文档设置为 `index.html`,并将任何 4xx 响应错误代码的错误页面设置为 `error.html`。 - 使用 `awss3apiget-bucket-acl--bucketyurisk.info` 命令验证存储桶 `yurisk.info` 中的 HTML 页面是否对所有人可读。 - 使用 `awss3apiget-bucket-website--bucketyurisk.info` 命令验证网站配置。 - 使用 `awss3apidelete-bucket-website--bucketyurisk.info` 命令从存储桶 `yurisk.info` 中删除网站配置(不会删除存储桶中的任何对象)。 - 使用 `awss3apiput-object--bucketyurisk.info--key/tag/nmap/index.html--website-redirect-locationhttp://yurisk.info--bodyC:/Users/yurisk.info/tag/nmap/index.html--aclpublic-read` 命令将本地文件 `index.html` 上传到存储桶 `yurisk.info` 中的 `/tag/nmap/` 位置,并将网站重定向到 `http://yurisk.info`,并将 ACL 设置为公共可读。

🤩 **创建预签名链接** - 使用 `awss3presigns3://yurisk.info/download.me--expires-in259200--profileawsadminprofile--regioneu-west-1` 命令创建到 S3 存储桶中对象的预签名链接。

😲 **其他操作** - 使用 `awss3apiput-object--bucketmybucket--keymyobject--bodyC:/Users/myuser/myobject` 命令将本地文件上传到存储桶。

🤯 **注意事项** - 请确保您已安装并配置了 AWS CLI。 - 请根据您的实际情况修改命令中的参数,例如存储桶名称、文件路径等。 - 请谨慎使用 `--force` 参数,因为它会强制删除非空存储桶。

👍 **总结** 本文介绍了使用 AWS CLI 管理 Amazon S3 存储桶的常用命令,希望能帮助您更好地理解和使用 AWS S3 服务。

🤯 **建议** 为了更深入地了解 AWS S3 服务,建议您参考官方文档和教程。

😨 **提示** 您也可以使用 AWS 管理控制台来管理 Amazon S3 存储桶,但使用 AWS CLI 可以更方便地进行自动化操作。

😎 **总结** 本文介绍了使用 AWS CLI 管理 Amazon S3 存储桶的常用命令,希望能帮助您更好地理解和使用 AWS S3 服务。

🤩 **建议** 为了更深入地了解 AWS S3 服务,建议您参考官方文档和教程。

😨 **提示** 您也可以使用 AWS 管理控制台来管理 Amazon S3 存储桶,但使用 AWS CLI 可以更方便地进行自动化操作。

Get a list of all the buckets under user account
Recursively list contents of a given bucket yurisk.info
Recursively list contents of a given bucket printing sizes in a friendly format
List contents of a bucket, add summary for number of objects and their total size
Get access-list associated with the bucket provided you have permissions to do so on this bucket
Create bucket in default region specified in configuration file
Create the bucket in a given region
Delete an empty bucket, if it is not empty fails with the error BucketNotEmpty
Force deleting non empty bucket provided that objects in it have not been versioned
Simulate removing without deleting anything
Delete recursively contents of a bucket, bucket itself is not deleted
Delete recursively all files in a bucket except JPEG and PNG
Delete only files with a given extension (here JPG)
Delete an empty bucket
Set the existing S3 bucket yurisk.info for hosting the website with the default served document being index.html and the error page for any 4xx response error codes being error.html
Make sure HTML pages of the bucket are accessible by anyone for reading
Verify the website configuration
Delete website configuration from a bucket (doesn't delete any objects iside the bucket)
Upload local file index.html to the bucket yurisk.info at the location /tag/nmap/ and set website redirection to the http://yurisk.info, also set ACL to public-read
Create expiring link/hot-link to the object in s3 bucket, pre-sign link

Get a list of all the buckets under user account

 aws s3 ls

Recursively list contents of a given bucket

The bucket here is yurisk.info.

 aws s3 ls yurisk.info --recursive

Recursively list contents of a given bucket printing sizes in a friendly format

 aws s3 ls yurisk.com --recursive --human

List contents of a bucket, add summary for number of objects and their total size

aws s3 ls yurisk.info --summarize --human --recursive

Get access-list associated with the bucket provided you have permissions to do so on this bucket

aws s3api get-bucket-acl --bucket yurisk.info

Create bucket in default region specified in configuration file

aws s3 mb s3://testbucket

Create the bucket in a given region

aws s3 mb s3://testbucket --region us-east-1

Delete an empty bucket, if it is not empty fails with the error BucketNotEmpty

aws s3 rb yurisk.info

Force deleting non empty bucket provided that objects in it have not been versioned

aws s3 rb s3://yurisk.com --force

Simulate removing without deleting anything

aws s3 rm s3://yurisk.info --dryrun --rec

Delete recursively contents of a bucket, bucket itself is not deleted

aws s3 rm s3://yurisk.info --recursive

Delete recursively all files in a bucket except JPEG and PNG

aws s3 rm s3://yurisk.info --recursive --exclude "*.jpg" --exclude "*.png" 

Delete only files with a given extension (here JPG)

aws s3 rm s3://yurisk.info --recursive --exclude "*" --include "*.jpg"

Delete an empty bucket

aws s3api delete-bucket --bucket yurisk.info

Set the existing S3 bucket yurisk.info for hosting the website with the default served document being index.html and the error page for any 4xx response error codes being error.html

aws s3 website s3://yurisk.info/ --index-document index.html --error-document error.html

Make sure HTML pages of the bucket are accessible by anyone for reading

aws s3api get-bucket-acl --bucket yurisk.info

Verify the website configuration

aws s3api get-bucket-website --bucket yurisk.info

Delete website configuration from a bucket (doesn't delete any objects inside the bucket)

aws s3api delete-bucket-website --bucket yurisk.info

Upload local file index.html to the bucket yurisk.info at the location /tag/nmap/ and set website redirection to the http://yurisk.info, also set ACL to public-read

aws s3api put-object --bucket yurisk.info --key /tag/nmap/index.html --website-redirect-location http://yurisk.info --body C:/Users/yurisk.info/tag/nmap/index.html --acl public-read

Create expiring link/hot-link to the object in s3 bucket, pre-sign link

aws s3 presign s3://yurisk.info/download.me --expires-in 259200 --profile awsadminprofile --region eu-west-1

Here:
download.me - object in S3 to create download link to. NOTE: You don't have to make this object public in any way, still, anyone with the link will have read access to it.
--expires-in 259200 - Expiration time starting from now in seconds/ Here it is set to 3 days. If this parameter is absent, the default expiration is 3600 seconds or 1 hour.
--region <name> - region location of the object, if it is different from the default one set in your AWS profile.
--profile - optional. Only needed if you ahve multiple AWS IAM user profiles configured on the host.

Output:

ttps://yurisk.info.s3.amazonaws.com/download.me?AWSAccessKeyId=AKIA2QEA3PKXP5TYM2GO&Signature=0WU7257sOAy9odrh6Fs88d0Vp94%3D&Expires=1599498917   

The expires here is epoch time when the link expires.

Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

AWS S3 命令行 存储桶 管理
相关文章