'Enabling CloudWatch logs for ApiGateway?

Im trying to use CloudFormation to configure CloudWatch logs for an ApiGateway. Please see the settings I need in the attached picture (I cant post images into this topic just yet as I'm a new user) CloudWatch logs for Api

Here is what I have tried so far however CloudWatch logs aren't enabled. Can anyone help with this?

apiGatewayDeployment:
    Type: AWS::ApiGateway::Deployment
    DependsOn: apiGatewayRootMethod
    Properties:
      Description: API Deployment
      RestApiId: !Ref apiGatewayApi
      StageName: MyApi
      StageDescription:
        MetricsEnabled: True
        MethodSettings:
          - ResourcePath: "/*"
            HttpMethod: "*"
            LoggingLevel: INFO
            MetricsEnabled: True


Solution 1:[1]

The AWS documentation is pretty unclear. After some days of shotgun programming, I found this. Here is a Cloudformation with API Gateway v2 that worked for me:

MyLogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: /aws/apigateway/nameOfLogGroupForCloudWatch
      RetentionInDays: 7
MyStage:
    Type: AWS::ApiGatewayV2::Stage
    Properties:
      # Begin CloudWatch
      AccessLogSettings:
        DestinationArn: !GetAtt MyLogGroup.Arn # This points to the log group above
        Format: '{ "requestId": "$context.requestId", "path": "$context.path", "routeKey": "$context.routeKey", "ip": "$context.identity.sourceIp", "requestTime": "$context.requestTime", "httpMethod": "$context.httpMethod","statusCode": $context.status }'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 josh hoegen