|
AWSTemplateFormatVersion: '2010-09-09' |
|
Transform: AWS::Serverless-2016-10-31 |
|
Description: Serverless patterns - Amazon API Gateway REST API with VPC Link integration |
|
|
|
Parameters: |
|
usecase: |
|
Description: What environment should be deployed |
|
Type: String |
|
AllowedValues: |
|
- "prod" |
|
- "stage" |
|
- "dev" |
|
Default: prod |
|
NlbInternalArn: |
|
Type: String |
|
Default: |
|
NlbDomainName: |
|
Description: NLB Domain Name |
|
Type: String |
|
Default: |
|
GatewayDomain: |
|
Description: ApiGateway domain |
|
Type: String |
|
Default: |
|
DomainConfiguration: |
|
Description: endpoint types of an Amazon API Gateway domain name |
|
Type: String |
|
Default: REGIONAL |
|
HostedZoneId: |
|
Default: |
|
Type: String |
|
Description: hosted zone ID for given domain name |
|
Resources: |
|
|
|
# REST API |
|
AppApi: |
|
Type: AWS::ApiGateway::RestApi |
|
Properties: |
|
Name: kong-apigw-rest-api-vpclink |
|
Description: VPC Link integraton REST API demo |
|
|
|
|
|
RootMethod: |
|
Type: AWS::ApiGateway::Method |
|
Properties: |
|
RestApiId: !Ref AppApi |
|
ResourceId: !GetAtt AppApi.RootResourceId |
|
HttpMethod: ANY |
|
AuthorizationType: NONE |
|
RequestParameters: |
|
method.request.path.proxy: true |
|
Integration: |
|
CacheKeyParameters: |
|
- 'method.request.path.proxy' |
|
Type: HTTP_PROXY |
|
ConnectionType: VPC_LINK |
|
IntegrationHttpMethod: ANY |
|
ConnectionId: !Ref VPCLinkRestNlbInternal |
|
Uri: !Sub https://${NlbDomainName} |
|
PassthroughBehavior: WHEN_NO_MATCH |
|
|
|
RootMethodProxy: |
|
DependsOn: |
|
- RootMethod |
|
Type: 'AWS::ApiGateway::Resource' |
|
Properties: |
|
ParentId: !GetAtt AppApi.RootResourceId |
|
RestApiId: !Ref AppApi |
|
PathPart: '{proxy+}' |
|
|
|
ProxyMethod: |
|
Type: AWS::ApiGateway::Method |
|
Properties: |
|
RestApiId: !Ref AppApi |
|
ResourceId: !Ref RootMethodProxy |
|
HttpMethod: ANY |
|
AuthorizationType: NONE |
|
RequestParameters: |
|
method.request.path.proxy: true |
|
Integration: |
|
CacheKeyParameters: |
|
- 'method.request.path.proxy' |
|
RequestParameters: |
|
integration.request.path.proxy: 'method.request.path.proxy' # 'request' should be 'integration.request' |
|
Type: HTTP_PROXY |
|
ConnectionType: VPC_LINK |
|
IntegrationHttpMethod: ANY |
|
ConnectionId: !Ref VPCLinkRestNlbInternal |
|
Uri: !Sub 'https://${NlbDomainName}/{proxy}' # Added single quotes around URI to avoid error in '&' character |
|
PassthroughBehavior: WHEN_NO_MATCH |
|
|
|
Deployment: |
|
Type: AWS::ApiGateway::Deployment |
|
DependsOn: |
|
- RootMethodProxy |
|
- ProxyMethod |
|
Properties: |
|
RestApiId: !Ref AppApi |
|
|
|
Stage: |
|
Type: AWS::ApiGateway::Stage |
|
Properties: |
|
StageName: Prod |
|
RestApiId: !Ref AppApi |
|
DeploymentId: !Ref Deployment |
|
|
|
|
|
VPCLinkRestNlbInternal: |
|
Type: AWS::ApiGateway::VpcLink |
|
Properties: |
|
Name: VPCLinkRestNlbInternal |
|
TargetArns: |
|
- !Ref NlbInternalArn |
|
|
|
|
|
GatewayDomainName: |
|
DependsOn: AppApi |
|
Type: 'AWS::ApiGateway::DomainName' |
|
Properties: |
|
DomainName: !Ref GatewayDomain |
|
# CertificateArn: !Sub "{{resolve:ssm:/${usecase}/infrastructure-ttm4j/certificate-arn:1}}" |
|
EndpointConfiguration: |
|
Types: |
|
- !Ref DomainConfiguration |
|
RegionalCertificateArn: !Sub "{{resolve:ssm:/${usecase}/infrastructure-ttm4j/certificate-arn:1}}" |
|
|
|
|
|
GatewayDomainRecordSetGroup: |
|
Type: AWS::Route53::RecordSetGroup |
|
Properties: |
|
HostedZoneId: !Ref HostedZoneId |
|
RecordSets: |
|
- Name: !Ref GatewayDomain |
|
Type: A |
|
AliasTarget: |
|
DNSName: !GetAtt GatewayDomainName.RegionalDomainName |
|
HostedZoneId: !GetAtt GatewayDomainName.RegionalHostedZoneId |
|
|
|
Mapping: |
|
Type: 'AWS::ApiGateway::BasePathMapping' |
|
Properties: |
|
DomainName: !Ref GatewayDomain |
|
RestApiId: !Ref AppApi |
|
Stage: !Ref Stage |
|
|
|
|
|
Outputs: |
|
|
|
# API Gateway endpoint to be used during tests |
|
AppApiEndpoint: |
|
Description: API Endpoint |
|
Value: !Sub "https://${AppApi}.execute-api.${AWS::Region}.amazonaws.com/Prod" |
|
|
|
|