【发布时间】:2019-08-12 04:00:12
【问题描述】:
我必须将保留策略添加到 API Gateway Cloudwatch 日志,因此我不能使用 aws 提供的策略来执行此操作,即 arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs
因此,我使用自定义策略创建了自己的角色:
ApiGatewayCloudWatchLogsRole:
Type: 'AWS::IAM::Role'
DependsOn: APIGFunctionLogGroup
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com
Action: 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: APIGatewayPushLogsPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
Effect: Allow
Action:
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
- 'logs:DescribeLogGroups'
- 'logs:DescribeLogStreams'
- 'logs:GetLogEvents'
- 'logs:FilterLogEvents'
Resource: '*'
然后创建 LogGroup 并保留为:
APIGFunctionLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
RetentionInDays: 30
LogGroupName: !Join
- ''
- - API-Gateway-Execution-Logs_
- !Ref MyRestApi
并将上面创建的角色传递给AWS::ApiGateway::Account
ApiGatewayAccount:
Type: 'AWS::ApiGateway::Account'
DependsOn: APIGFunctionLogGroup
Properties:
CloudWatchRoleArn: !GetAtt
- ApiGatewayCloudWatchLogsRole
- Arn
但在部署我的 API 网关时,我收到以下错误:
我也有信任策略,但没有创建 API 网关帐户。
【问题讨论】:
标签: amazon-web-services amazon-cloudformation aws-api-gateway amazon-cloudwatch