UNPKG

@incdevco/framework

Version:
277 lines 7.75 kB
{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "everything to make a lambda function into an api with a custom domain name.", "Parameters": { "CachingEnabled": { "Default": "false", "Description": "", "Type": "String" }, "CertificateArn": { "Description": "arn for ssl certificate for domain name", "Type": "String" }, "CustomCFResourceFunctionArn": { "Type": "String" }, "Description": { "Type": "String" }, "DomainName": { "Description": "domain name to use for the api", "Type": "String" }, "EventLogArn": { "Default": "", "Type": "String" }, "EventLogSubscriptionRoleArn": { "Default": "", "Type": "String" }, "FunctionArn": { "Description": "lambda function arn passed to resources stack template", "Type": "String" }, "HostedZoneId": { "Type": "String" }, "Name": { "Type": "String" }, "ResourcesStackTemplateURL": { "Description": "template url for the resources for the api", "Type": "String" }, "Stage": { "Description": "stage of the stack", "Type": "String" }, "Timestamp": { "Type": "String" }, "ThrottlingBurstLimit": { "Default": 2000, "Description": "", "Type": "Number" }, "ThrottlingRateLimit": { "Default": 1000.0, "Description": "", "Type": "Number" } }, "Conditions": { "HasEventLog": {"Fn::Not": [{"Fn::Equals": ["", {"Ref": "EventLogArn"}]}]}, "IsCachingEnabled": {"Fn::Equals": [{"Ref": "CachingEnabled"}, "true"]} }, "Mappings": {}, "Resources": { "BasePathMapping": { "Type": "AWS::ApiGateway::BasePathMapping", "DeletionPolicy": "Retain", "DependsOn": [ "CustomDomainName", "Deployment" ], "Properties": { "BasePath": "", "DomainName": {"Ref": "DomainName"}, "RestApiId": {"Ref": "RestApi"}, "Stage": {"Ref": "Stage"} } }, "BodyAndParamsValidator": { "Type": "Custom::ApiGatewayRequestValidator", "Properties": { "ServiceToken": {"Ref": "CustomCFResourceFunctionArn"}, "Options": { "restApiId": {"Ref": "RestApi"}, "name": "body-and-params-only", "validateRequestBody": true, "validateRequestParameters": true } } }, "BodyValidator": { "Type": "Custom::ApiGatewayRequestValidator", "Properties": { "ServiceToken": {"Ref": "CustomCFResourceFunctionArn"}, "Options": { "restApiId": {"Ref": "RestApi"}, "name": "body-only", "validateRequestBody": true, "validateRequestParameters": false } } }, "CustomDomainName": { "Type": "Custom::ApiGatewayCustomDomainName", "Properties": { "ServiceToken": {"Ref": "CustomCFResourceFunctionArn"}, "Options": { "domainName": {"Ref": "DomainName"}, "certificateArn": {"Ref": "CertificateArn"} } } }, "Deployment": { "Type": "Custom::ApiGatewayDeployment", "DependsOn": [ "Resources" ], "Properties": { "ServiceToken": {"Ref": "CustomCFResourceFunctionArn"}, "Options": { "cacheClusterEnabled": {"Fn::If": [ "IsCachingEnabled", true, false ]}, "description": "", "restApiId": {"Ref": "RestApi"}, "stageDescription": "", "stageName": {"Ref": "Stage"}, "variables": {}, "methodSettings": { "*/*": { "dataTraceEnabled": true, "throttlingRateLimit": {"Ref": "ThrottlingRateLimit"}, "metricsEnabled": true, "throttlingBurstLimit": {"Ref": "ThrottlingBurstLimit"}, "cachingEnabled": {"Fn::If": [ "IsCachingEnabled", true, false ]}, "loggingLevel": "INFO" } } }, "Timestamp": {"Ref": "Timestamp"} } }, "DeploymentLogSubscription": { "Type": "Custom::CloudWatchSubscriptionFilter", "Condition": "HasEventLog", "DependsOn": [ "Deployment" ], "Properties": { "ServiceToken": {"Fn::ImportValue": "CustomCFResourceFunctionArn"}, "Options": { "destinationArn": {"Ref": "EventLogArn"}, "filterName": "all", "filterPattern": "", "logGroupName": {"Fn::Join": ["", [ "API-Gateway-Execution-Logs_", {"Ref": "RestApi"}, "/", {"Ref": "Stage"} ]]}, "roleArn": {"Ref": "EventLogSubscriptionRoleArn"} } } }, "ParamsValidator": { "Type": "Custom::ApiGatewayRequestValidator", "Properties": { "ServiceToken": {"Ref": "CustomCFResourceFunctionArn"}, "Options": { "restApiId": {"Ref": "RestApi"}, "name": "params-only", "validateRequestBody": false, "validateRequestParameters": true } } }, "Permission": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": {"Ref": "FunctionArn"}, "Principal": "apigateway.amazonaws.com", "SourceArn": {"Fn::Join": ["", [ "arn:aws:execute-api:", {"Ref": "AWS::Region"}, ":", {"Ref": "AWS::AccountId"}, ":", {"Ref": "RestApi"}, "/*/*/*" ]]} } }, "RecordSetGroup": { "Type": "AWS::Route53::RecordSetGroup", "Properties": { "HostedZoneId": {"Ref": "HostedZoneId"}, "RecordSets": [ { "Name": {"Ref": "DomainName"}, "Type": "A", "AliasTarget": { "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": {"Ref": "CustomDomainName"} } } ] } }, "Resources": { "Type": "AWS::CloudFormation::Stack", "Properties": { "NotificationARNs": {"Ref": "AWS::NotificationARNs"}, "Parameters": { "BodyAndParamsValidatorId": {"Ref": "BodyAndParamsValidator"}, "BodyValidatorId": {"Ref": "BodyValidator"}, "ParamsValidatorId": {"Ref": "ParamsValidator"}, "FunctionUri": {"Fn::Join": ["", [ "arn:aws:apigateway:", {"Ref": "AWS::Region"}, ":lambda:path/2015-03-31/functions/", {"Ref": "FunctionArn"}, "/invocations" ]]}, "RestApiId": {"Ref": "RestApi"}, "RootResourceId": {"Fn::GetAtt": ["RestApi", "RootResourceId"]}, "Stage": {"Ref": "Stage"} }, "TemplateURL": {"Ref": "ResourcesStackTemplateURL"} } }, "RestApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { "Description": {"Ref": "Description"}, "Name": {"Ref": "Name"} } } }, "Outputs": { "BodyAndParamsValidatorId": { "Value": {"Ref": "BodyAndParamsValidator"} }, "BodyValidatorId": { "Value": {"Ref": "BodyValidator"} }, "Endpoint": { "Value": {"Fn::Join": ["", [ "https://", {"Ref": "DomainName"} ]]} }, "ParamsValidatorId": { "Value": {"Ref": "ParamsValidator"} }, "Region": { "Value": {"Ref": "AWS::Region"} }, "RestApiId": { "Value": {"Ref": "RestApi"} }, "RootResourceId": { "Value": {"Fn::GetAtt": ["RestApi", "RootResourceId"]} } } }