Ben Jonson
Ben Jonson

Reputation: 739

How to fix Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template

I am trying to set the ApiGatewayRestApi to an environment variable. I am getting the following error while trying to deploy using "sls deploy" :

The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template.

Here is the serverless.yml file:

service: upranklytoolsApi
frameworkVersion: '2 || 3'

provider:
  name: aws
  runtime: nodejs12.x
  region: us-east-1
  stage: dev
  apiGateway:
    minimumCompressionSize: 1024
  
  environment:
    RestApiId:  
      Ref: ApiGatewayRestApi
 

  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "dynamodb:DescribeTable"
        - "dynamodb:PutItem"
        - "dynamodb:Get*"
        - "dynamodb:Scan*"
        - "dynamodb:Query"
        - "dynamodb:UpdateItem"
        - "dynamodb:DeleteItem"
        - "dynamodb:BatchWriteItem"
        - "lambda: InvokeFunction"
        - "lambda: InvokeAsync"
        - "dynamodb:ConditionCheckItem"
      Resource: arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/${self:service}-ranktrackerTable-${self:provider.stage}
    
    - Effect: Allow
      Action:
        - cognito-idp:CreateUserPool
        - cognito-idp:DeleteUserPool
        - cognito-idp:UpdateUserPool
        - cognito-idp:DescribeUserPool
      Resource: '*'

custom:
  serverless-offline:
    port: 5000
  dynamodb:
    stages: 
      - dev 
    start:
      port: 8000
      inMemory: true 
      migrate: true 


plugins:
  - serverless-dynamodb-local
  - serverless-step-functions
  - serverless-offline-lambda-invoke
  - serverless-offline
 
functions:
  createKey:
    handler: handlers/createKey.main
    events:
      - httpApi: 
          path: /keyw
          method: post 
  updateKey: 
    handler: handlers/updateKeyw.main 
    events: 
      - httpApi: 
          path: /{userName}/keyw/{id}
          method: put
  
 
 
  
  # CREDITS
  addCreditTransaction:
    handler: handlers/addCreditTransaction.main
    events: 
      - httpApi: 
          path: /{userName}/credit-transactions/{transType}
          method: post
 
  
resources:
  Resources:
    RankTrackerTable:
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Delete
      Properties:
        TableName: ${self:service}-rankTable-${sls:stage}
        AttributeDefinitions: 
          - AttributeName: "pk"
            AttributeType: "S"
          - AttributeName: "sk"
            AttributeType: "S"
          - AttributeName: "gsi1pk"
            AttributeType: "S"
          - AttributeName: "gsi1sk"
            AttributeType: "S"
          - AttributeName: "gsi3pk"
            AttributeType: "S"
        KeySchema: 
          - AttributeName: "pk"
            KeyType: "HASH"
          - AttributeName: "sk"
            KeyType: "RANGE"
        BillingMode: "PAY_PER_REQUEST"
        GlobalSecondaryIndexes:
          - IndexName: 'gsi1'
            KeySchema:
            - AttributeName: "gsi1pk"
              KeyType: "HASH"
            - AttributeName: "gsi1sk"
              KeyType: "RANGE"
            Projection:
              ProjectionType: ALL
          - IndexName: "gsi3"
            KeySchema:
             - AttributeName : "gsi3pk"
               KeyType: "HASH"
            Projection: 
              ProjectionType: ALL
        
    CognitoUserPool:
      Type: AWS::Cognito::UserPool
      Properties:
        UserPoolName: ${self:service}-${self:provider.stage}-user-pool
        UsernameAttributes:
          - email
        AutoVerifiedAttributes:
          - email
 

    CognitoUserPoolClient:
      Type: AWS::Cognito::UserPoolClient
      Properties:
          ClientName: ${self:service}-${self:provider.stage}-user-pool-client
          UserPoolId:
              Ref: CognitoUserPool
          ExplicitAuthFlows:
              - ADMIN_NO_SRP_AUTH
          GenerateSecret: false

Upvotes: 5

Views: 7312

Answers (1)

Ben Jonson
Ben Jonson

Reputation: 739

I have found the error. Instead of using 'ApiGatewayRestApi" if I use "HttpApi" I get the desired result.

environment:
    RestApiId:  
      Ref: HttpApi

Upvotes: 5

Related Questions