Update July 5, 2017 : AWS::ApiGateway::DomainName now available, so the user resource is no longer needed for this part.
Original post dated December 24, 2016:
- Enable cloud browsing logs for stage in cloud information template
To enable CloudWatch logs for the ApiGateway stage using CloudFormation for each method call in your API, you need to set the DataTraceEnabled property to true for all methods in the AWS::ApiGateway::Stage resource.
As stated in the "Configure Stage" section of the documentation, you will also need to associate your API Gateway account with the appropriate IAM permissions to transfer data to CloudWatch logs. To do this, you will also need to create an AWS::ApiGateway::Account resource that references the IAM role that contains the AmazonAPIGatewayPushToCloudWatchLogs managed policy, as described in the example documentation:
CloudWatchRole: Type: "AWS::IAM::Role" Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Principal: Service: - "apigateway.amazonaws.com" Action: "sts:AssumeRole" Path: "/" ManagedPolicyArns: - "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" Account: Type: "AWS::ApiGateway::Account" Properties: CloudWatchRoleArn: "Fn::GetAtt": - CloudWatchRole - Arn
- Assign a stage to a custom domain name in a cloud information template
Unfortunately, CloudFormation does not provide an official resource matching the DomainName API APIGateway REST. Fortunately, the Carl Nordenfelt unofficial API gateway for the CloudFormation project provides Custom::ApiDomainName . Here is an example provided in the documentation:
TestApiDomainName: Type: Custom::ApiDomainName Properties: ServiceToken: {Lambda_Function_ARN} domainName: example.com certificateName: testCertificate certificateBody": "-----BEGIN CERTIFICATE-----line1 line2 ... -----END CERTIFICATE-----" certificateChain: "-----BEGIN CERTIFICATE-----line1 line2 ... -----END CERTIFICATE-----" certificatePrivateKey: "-----BEGIN RSA PRIVATE KEY-----line1 line2 ... -----END RSA PRIVATE KEY-----"
Also note that once the domain name has been created, you must create a Route53 alias record that points to !GetAtt TestApiDomainName.distributionDomainName and the static CloudFront zone identifier ( Z2FDTNDATAQYW2 ), for example:
myDNSRecord: Type: AWS::Route53::RecordSet Properties: HostedZoneName: !Ref HostedZone Name: !Ref DomainName Type: A AliasTarget: DNSName: !GetAtt TestApiDomainName.distributionDomainName HostedZoneId: Z2FDTNDATAQYW2
source share