HttpApi invalid error on nested stack

0

Im trying to create a nested stack on a cloudformation template, i have declared in the parent application a reference to the http api we are using, and use this api in the child template. When i try to do the build with sam, it throws this error: "E0001 Error transforming template:ApiId must be a valid reference to an 'AWS::Serverless::HttpApi' resource in same template."

Parent template declaration:

childStack:
    Type: "AWS::Serverless::Application"
    Properties:
      Location: ./child.yaml
      Parameters:
        ApiId: !Ref ApiReference

Child template declaration:

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

Parameters:
  ApiId:
    Type: string

Globals:
  Function:
    Runtime: !Ref "AWS::NoValue"
    Handler: !Ref "AWS::NoValue"
    Layers: !Ref "AWS::NoValue"

Resources:
  lambdaFunctionLogGroup:
    Type: 'AWS::Logs::LogGroup'
    Properties:
      Location: ./parent.yaml
      LogGroupName: !Join
        - '/'
        - - '/aws/lambda'
          - !Ref 'TournamentSubscriptionFunction'
      RetentionInDays:
        !FindInMap [Service, !Ref EnvironmentName, LogRetentionInDays]

  lambdaFunction:
    Location: ./parent.yaml
    Type: AWS::Serverless::Function
    Properties:
      Description: Image validation for identity verification
      FunctionName: !Sub '${EnvironmentName}-lambda'
      PackageType: Image
      Architectures: ['arm64']
      Environment:
        Variables:
          ExampleVariable
      Policies:
        - CloudWatchLambdaInsightsExecutionRolePolicy
      Events:
        Name:
          Type: HttpApi
          Properties:
            Path: /event-client/api/lambda
            Method: POST
            ApiId: !Ref ApiReference
            Auth:
              Authorizer: OAuth2Authorizer
      VpcConfig:
        SubnetIds: !Split
          - ','
          - Fn::ImportValue: !Sub '${EnvironmentName}-PrivateSubnets'
      Tags:
        Environment: !Sub '${EnvironmentName}'
    Metadata:
      DockerTag: nodejs16.x-v1
      DockerContext: ../dist/src/client/lambda-route
      Dockerfile: Dockerfile
1 Answer
0

According to the docs:

This cannot reference an AWS::Serverless::HttpApi resource defined in another template.
profile pictureAWS
EXPERT
kentrad
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions