I want to set a role to my API gateway so that I can see the logs for any errors. But while trying to do this, I am getting the below error.
Failed to create change set. Current status: FAILED
I am not sure if there is a Role property in AWS::Serverless::Api My editor says "Unknown resource type property: Role" when I set the Role here.
Here is my CF script.
MyApiGateway:
Type: AWS::Serverless::Api
Properties:
Name:
!Sub
- '${TheEnv}-${TheAppNameForResources}-api'
- TheEnv: !Ref Environment
TheAppNameForResources: !Ref AppNameForResources
TheBucketRegion: !Ref AWS::Region
TracingEnabled: true
OpenApiVersion: 3.0.2
Cors:
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
AllowMethods: "'*'"
AllowOrigin: "'*'"
StageName: test
Role: !GetAtt APICloudwatchLogRole.Arn
DefinitionBody:
swagger: "2.0"
paths:
/batch:
get:
x-amazon-apigateway-integration:
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-
31/functions/${MyLambdaFunction.Arn}/invocations
httpMethod: GET
type: "aws_proxy"
APICloudwatchLogRole:
Type: AWS::IAM::Role
Properties:
RoleName:
!Sub
- "${TheAppNameForResources}-${TheEnvName}-cw-role-for-api"
- TheAppNameForResources: !Ref AppNameForResources
TheEnvName: !Ref Environment
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: "apigateway.amazonaws.com"
Action: ['sts:AssumeRole']
Policies:
- PolicyName:
!Sub
- "${TheAppNameForResources}-${TheEnvName}-cw-role-for-api"
- TheAppNameForResources: !Ref AppNameForResources
TheEnvName: !Ref Environment
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: "*"
Could some one know if there is a way to set a role to API gateway when using AWS::Serverless::Api? I also tried deleting the entire stack and re-creating, but still no luck.
Thanks
You should be able to attach a resource-based policy to the
AWS::Serverless::Apiusing theApiAuth.ResourcePolicyStatement.CustomStatementsattribute.See example.