AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'

Parameters:
  ECSStack:
    Type: String
  AppStack:
    Type: String
  CognitoStackName:
    Type: String

Resources:
  MyAPI:
    Type: AWS::Serverless::Api
    Properties:
      StageName: dev
      EndpointConfiguration: EDGE
      DefinitionBody:
        openapi: 3.0.1
        paths:
          /:
            get:
              x-amazon-apigateway-integration:
                connectionId:
                  Fn::ImportValue:
                    !Sub ${ECSStack}-VPCLink
                uri:
                  Fn::Sub:
                    - http://${EndpointUri}/
                    - EndpointUri: !ImportValue
                        Fn::Sub: ${AppStack}-PrivateDNSEndpoint

          securitySchemes:
            cognitoAuth:
              type: apiKey
              name: Authorization
              in: header
              x-amazon-apigateway-authtype: cognito_user_pools
              x-amazon-apigateway-authorizer:
                type: cognito_user_pools
                providerARNs:
                  - Fn::ImportValue: !Sub ${CognitoStackName}-Arn
