"Invalid API identifier" when referencing AWS::Serverless::Api resource ID

0

I have a CloudFormation template managing a series of nested templates. One of these templates is a SAM application, which creates a AWS::Serverless::Api resource and outputs this resource reference. I am trying to add another route to this API in a separate nested template (or the parent template, but I get the same error here). My setup looks like this (simplified):

# parent template
AWSTemplateFormatVersion: 2010-09-09

Resources:
  ContactFormApi:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: ./node_modules/@dawaltconley/contact-api/dist/build/template.yaml
  MailingList:
    Type: AWS::CloudFormation::Stack
    DependsOn:
      - ContactFormApi
    Properties:
      TemplateURL: ./mailing-list.template.yaml
      Parameters:
        ApiGatewayId: !GetAtt ContactFormApi.Outputs.ApiId
# ContactFormApi template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  ContactApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod

Outputs:
  ApiId:
    Value: !Ref ContactApi
# MailingList template
AWSTemplateFormatVersion: 2010-09-09

Parameters:
  ApiGatewayId:
    Type: String

Resources:
  ApiIntegration:
    Type: AWS::ApiGatewayV2::Integration
    Properties:
      ApiId: !Ref ApiGatewayId
      IntegrationMethod: GET
      IntegrationType: AWS_PROXY
      IntegrationUri: !GetAtt LambdaFunction.Arn

  ApiRoute:
    Type: AWS::ApiGatewayV2::Route
    DependsOn:
      - LambdaFunction
      - ApiIntegration
    Properties:
      ApiId: !Ref ApiGatewayId
      RouteKey: GET /subscribe
      Target: !Sub 'integrations/${ApiIntegration}'

  LambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      Code: directory
      Handler: index.lambdaHandler
      Runtime: nodejs18.x
      Timeout: 10
      Architectures:
        - x86_64
      Role: !GetAtt LambdaRole.Arn

  LambdaRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service: lambda.amazonaws.com
            Action: sts:AssumeRole

I am using aws cloudformation package and aws cloudformation deploy to deploy this template. When I do, it fails on the creation of the ApiIntegration resource, and gives the following error (I replaced my account number with 123456):

Invalid API identifier specified 123456:knyawz3heb (Service: AmazonApiGatewayV2; Status Code: 404; Error Code: NotFoundException; Request ID: cb5323c0-4cef-447b-9cbd-b86195321bca; Proxy: null)

I have confirmed that knyawz3heb is indeed the ID of the API Gateway resource I want to reference, that this is the value of the ApiGatewayId parameter that the AWS console shows for the failed MailingList template, I am pretty sure that this resource exists at the time that the ApiIntegration resource is being created.

I am wondering if there's anything I'm doing wrong here that I've totally missed? Is there a correct way to reference the API resource ID created by SAM? Is it possible that the Serverless transform is turning resource_id into account_number:resource_id? I tried turning it back with !Select [1, !Split [':', !Ref ApiGatewayId]], but this failed (no index 1).

Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen