如果您在尝试部署 API 网关(尤其是 Stage)时遇到以下错误,则需要确保针对您的账户设置了 CloudWatch ern。
Blah_V1Stage (V1Stage) CloudWatch Logs 角色 ARN 必须在账户设置中设置才能启用日志记录 (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: a855c5c5-b64b-4b22-85e8-703909b4c850)
const cloudWatchRole = new iam.Role(this, this.prefix + "_cloudwatchrole",
{
assumedBy: new iam.CompositePrincipal(new iam.ServicePrincipal("apigateway.amazonaws.com")),
roleName: this.prefix + "_cloudwatchrole"
});
cloudWatchRole.addManagedPolicy(
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonAPIGatewayPushToCloudWatchLogs'))
const account = new apigateway.CfnAccount(this, "account",
{
cloudWatchRoleArn: cloudWatchRole.roleArn
});
Run Code Online (Sandbox Code Playgroud) 我第一次玩 boto3。我想循环遍历已填充 s3 存储桶的数组,然后获取每个存储桶的策略状态,尽管我收到错误且不确定原因。它适用于数组的第一个索引,但之后会出错。为什么?
#!/usr/bin/python3
import boto3
all_buckets=[]
session = boto3.Session(profile_name='default')
s3 = session.client('s3')
def get_bucket_list():
for i in s3.list_buckets()['Buckets']:
all_buckets.append(f' {i["Name"]}')
get_bucket_list()
for j in all_buckets:
k = (j.strip())
policy = s3.get_bucket_policy_status(Bucket=k)
print(policy)
Run Code Online (Sandbox Code Playgroud)
错误:(注意:对 AWS ID 的引用不是真实的)
{'ResponseMetadata': {'RequestId': 'D237HE2EPLFX78KV', 'HostId': 'A23zqZFjzk2qeqkPRn0ano3KBiatr9YoPVB94EFGfh0T/ojbNbOkAyz82hibmijgVox3vTrfGz=', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amz-id-2': 'A23zqZFjzk2qeqkPRn0ano3KBiatr9YoPVB94EFGfh0T/ojbNbOkAyz82hibmijgVox3vTrfGz=', 'x-amz-request-id': 'D237HE2EPLFX78KV', 'date': 'Thu, 04 Mar 2021 00:06:33 GMT', 'transfer-encoding': 'chunked', 'server': 'AmazonS3'}, 'RetryAttempts': 0}, 'PolicyStatus': {'IsPublic': False}}
Traceback (most recent call last):
File "./test2.py", line 17, in <module>
policy = s3.get_bucket_policy_status(Bucket=k) …Run Code Online (Sandbox Code Playgroud)