使用 Amazon CLI 的 Amazon S3 Storage Lens 示例
Amazon S3 Storage Lens 总结您的使用率和活动指标,并在 Amazon S3 控制台主页(存储桶)页面、交互式控制面板上的帐户快照中显示信息,或通过可下载为 CSV 或 Parquet 格式的指标导出显示信息。您可以使用控制面板可视化见解和趋势,标记异常,并接收有关优化存储成本和应用数据保护最佳实践的建议。您可以通过 Amazon Web Services Management Console、Amazon CLI、Amazon 开发工具包或 REST API 使用 S3 Storage Lens。有关更多信息,请参阅使用 Amazon S3 Storage Lens 评估存储活动和使用情况。
以下示例说明如何将 S3 Storage Lens 与 Amazon Command Line Interface 配合使用。
主题
使用 Amazon S3 Storage Lens 的帮助程序文件
使用以下 JSON 文件作为示例的关键输入。
S3 Storage Lens 示例配置 JSON
例 config.json
包含 S3 Storage Lens 组织级高级指标和建议配置的详细信息。
注意
高级指标和建议需支付额外费用。有关详细信息,请参阅高级指标和建议。
{ "Id": "SampleS3StorageLensConfiguration",//Use this property to identify S3 Storage Lens configuration."AwsOrg": {//Use this property when enabling S3 Storage Lens for Amazon Organizations"Arn": "arn:aws:organizations::222222222222:organization/o-abcdefgh" }, "AccountLevel": { "ActivityMetrics": { "IsEnabled":true}, "BucketLevel": { "ActivityMetrics": { "IsEnabled":true//Mark this as false if you only want Free Metrics metrics.}, "PrefixLevel":{ "StorageMetrics":{ "IsEnabled":true,//Mark this as false if you only want Free Metrics metrics."SelectionCriteria":{ "MaxDepth":5, "MinStorageBytesPercentage":1.25, "Delimiter":"/" } } } } }, "Exclude": {//Replace with include if you prefer to include regions."Regions": [ "eu-west-1" ], "Buckets": [//This attribute is not supported for Organizations-level configurations."arn:aws:s3:::source_bucket1" ] }, "IsEnabled":true,//Whether the configuration is enabled"DataExport": {//Details about the metrics export"S3BucketDestination": { "OutputSchemaVersion": "V_1", "Format": "CSV",//You can add "Parquet" if you prefer."AccountId": "ExampleAWSAccountNo8", "Arn": "arn:aws:s3:::destination-bucket-name",// The destination bucket for your metrics export must be in the same Region as your S3 Storage Lens configuration."Prefix": "prefix-for-your-export-destination", "Encryption": { "SSES3": {} } } } }
S3 Storage Lens 示例配置标签 JSON
例 tags.json
[ { "Key": "key1", "Value": "value1" }, { "Key": "key2", "Value": "value2" } ]
S3 Storage Lens 示例配置 IAM 权限
例 permissions.json - 特定控制面板名称
此示例策略显示具有指定特定控制面板名称的 S3 Storage Lens IAM 权限。将 和 your-dashboard-name 替换为您自己的值。example-account-id
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetStorageLensConfiguration", "s3:DeleteStorageLensConfiguration", "s3:PutStorageLensConfiguration" ], "Condition": { "StringEquals": { "aws:ResourceTag/key1": "value1" } }, "Resource": "arn:aws:s3:us-east-1:example-account-id:storage-lens/your-dashboard-name" } ] }
例 permissions.json - 没有特定的控制面板名称
此示例策略显示了未指定特定控制面板名称的 S3 Storage Lens IAM 权限。将 替换为您的 Amazon Web Services 账户 ID。example-account-id
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetStorageLensConfiguration", "s3:DeleteStorageLensConfiguration", "s3:PutStorageLensConfiguration" ], "Condition": { "StringEquals": { "aws:ResourceTag/key1": "value1" } }, "Resource": "arn:aws:s3:us-east-1:example-account-id:storage-lens/*" } ] }
Amazon S3 Storage Lens 配置与 Amazon CLI 配合使用
您可以使用 Amazon CLI 列出、创建、获取和更新 S3 Storage Lens 配置。以下示例使用帮助程序 JSON 文件进行关键输入。
主题
放置 S3 Storage Lens 配置
例 放置 S3 Storage Lens 配置
aws s3control put-storage-lens-configuration --account-id=222222222222--config-id=your-configuration-id--region=us-east-1--storage-lens-configuration=file://./config.json--tags=file://./tags.json
放置没有标签的 S3 Storage Lens 配置
例 放置 S3 Storage Lens 配置
aws s3control put-storage-lens-configuration --account-id=222222222222--config-id=your-configuration-id--region=us-east-1--storage-lens-configuration=file://./config.json
获取 S3 Storage Lens 配置
例 获取 S3 Storage Lens 配置
aws s3control get-storage-lens-configuration --account-id=222222222222--config-id=your-configuration-id--region=us-east-1
列出没有下一个令牌的 S3 Storage Lens 配置
例 列出没有下一个令牌的 S3 Storage Lens 配置
aws s3control list-storage-lens-configurations --account-id=222222222222--region=us-east-1
列出 S3 Storage Lens 配置
例 列出 S3 Storage Lens 配置
aws s3control list-storage-lens-configurations --account-id=222222222222--region=us-east-1--next-token=abcdefghij1234
删除 S3 Storage Lens 配置
例 删除 S3 Storage Lens 配置
aws s3control delete-storage-lens-configuration --account-id=222222222222--region=us-east-1--config-id=your-configuration-id
将标签放置到 S3 Storage Lens 配置
例 将标签放置到 S3 Storage Lens 配置
aws s3control put-storage-lens-configuration-tagging --account-id=222222222222--region=us-east-1--config-id=your-configuration-id--tags=file://./tags.json
获取 S3 Storage Lens 配置标签
例 获取 S3 Storage Lens 配置标签
aws s3control get-storage-lens-configuration-tagging --account-id=222222222222--region=us-east-1--config-id=your-configuration-id
删除 S3 Storage Lens 配置标签
例 删除 S3 Storage Lens 配置标签
aws s3control delete-storage-lens-configuration-tagging --account-id=222222222222--region=us-east-1--config-id=your-configuration-id
通过 Amazon CLI 来结合使用 Amazon S3 Storage Lens 与 Amazon Organizations
使用 Amazon S3 Storage Lens 收集属于 Amazon Organizations 层次结构的所有账户的存储指标和使用情况数据。有关更多信息,请参阅将 Amazon S3 Storage Lens 与 Amazon Organizations 结合使用。
主题
为 S3 Storage Lens 启用组织可信访问权限
例 为 S3 Storage Lens 启用组织可信访问权限
aws organizations enable-aws-service-access --service-principal storage-lens.s3.amazonaws.com
为 S3 Storage Lens 禁用组织可信访问权限
例 为 S3 Storage Lens 禁用组织可信访问权限
aws organizations disable-aws-service-access --service-principal storage-lens.s3.amazonaws.com
为 S3 Storage Lens 注册组织委托管理员
例 为 S3 Storage Lens 注册组织委托管理员
aws organizations register-delegated-administrator --service-principal storage-lens.s3.amazonaws.com —account-id 123456789012
为 S3 Storage Lens 取消注册组织委托管理员
例 为 S3 Storage Lens 取消注册组织委托管理员
aws organizations deregister-delegated-administrator --service-principal storage-lens.s3.amazonaws.com —account-id 123456789012