serverless-plugin-additional-stacks icon indicating copy to clipboard operation
serverless-plugin-additional-stacks copied to clipboard

The CloudFormation template is invalid

Open cramhead opened this issue 6 years ago • 0 comments

The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [SampleStore, UserDynamoDbTable, SessionDynamoDbTable] in the Resources block of the template

When I move the resource definitions to the additionalStacks area my project has an error referencing the resources. I expect it's because I'm referring to them in the now external sample-api, when they are defined in the permanent cloud formation template. Would there be an example of how to do this?

service:
  name: sample-api
plugins:
  - serverless-plugin-additional-stacks
  - serverless-webpack
  - serverless-dynamodb-local
  - serverless-offline # serverless-offline needs to be last in the list

provider:
  name: aws
  runtime: nodejs8.10
  memorySize: 512
  stage: ${opt:stage, 'uat'}
  profile: ${self:custom.profiles.${self:provider.stage}}
  region: ${opt:region, 'us-west-2'}
  versionFunctions: false
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource:
        - { "Fn::Join" : ["", [" arn:aws:dynamodb:::", { "Ref" : "UserDynamoDbTable" } , "" ]]}
        - { "Fn::Join" : ["", [" arn:aws:dynamodb:::", { "Ref" : "SessionDynamoDbTable" } , "" ]]}
    - Effect: Allow
      Action:
        - s3:ListBucket
      Resource:  { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "SampleStore" } , "/*" ]]}
    - Effect: Allow
      Action: 
        - s3:PutObject
        - s3:GetObject
        - s3:DeleteObject
      Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "SampleStore" } , "/*" ]]} 
    - Effect: Allow
      Action:
        - SES:SendEmail
        - SES:SendRawEmail
        - SNS:Publish
        - SES:Publish
      Resource: "*"
  environment:
    USER_TABLE: users-${self:provider.stage}
    SESSION_TABLE: session-${self:provider.stage}
    SAMPLE_STORAGE: a-good-bucket-name-${self:provider.stage}
    LOG_LEVEL: INFO

custom:
  defaultStage: uat
  profiles:
    uat: profile-dev
    stg: profile-stg
    prod: profile-prod
  webpack:
    includeModules: true
  serverless-offline:
    port: 5000
  dynamodb:
    start:
      port: 8000
      inMemory: true
      migrate: true
      seed: true
      noStart: true
    seed:
      test:
        sources:
          - table: users-dev
            sources: [./seed/users.json]
  additionalStacks:
    permanent:
      Deploy: Before
      Resources:
        UserDynamoDbTable:
          Type: 'AWS::DynamoDB::Table'
          DeletionPolicy: Retain
          Properties:
            AttributeDefinitions:
              -
                AttributeName: userId
                AttributeType: S
            KeySchema:
              -
                AttributeName: userId
                KeyType: HASH
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
            TableName: users-${self:provider.stage}
        SessionDynamoDbTable:
          Type: 'AWS::DynamoDB::Table'
          DeletionPolicy: Retain
          Properties:
            AttributeDefinitions:
              -
                AttributeName: id
                AttributeType: S
            KeySchema:
              -
                AttributeName: id
                KeyType: HASH
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
            TableName: session-${self:provider.stage}
        SampleStore:
          Type: AWS::S3::Bucket
          Properties:
            BucketName: a-good-bucket-name-${self:provider.stage}

functions:
  getHello:
    handler: src/hello.getHello
    events:
      - http:
          method: get
          path: canvas/get/{id}
          cors: true

cramhead avatar Jul 10 '18 23:07 cramhead