Search code examples
aws-cloudformationserverless-framework

!ImportValue in Serverless Framework not working


I'm attempting to export a DynamoDb StreamArn from a stack created in CloudFormation, then reference the export using !ImportValue in the serverless.yml.

But I'm getting this error message:

unknown tag !<!ImportValue> in "/codebuild/output/src/serverless.yml"

The cloudformation and serverless.yml are defined as below. Any help appreciated.

StackA.yml

AWSTemplateFormatVersion: 2010-09-09
Description: Resources for the registration site

Resources:
  ClientTable:
    Type: AWS::DynamoDB::Table
    DeletionPolicy: Retain
    Properties:
      TableName: client
      AttributeDefinitions:
        - AttributeName: id
          AttributeType: S
      KeySchema:
        - AttributeName: id
          KeyType: HASH
      ProvisionedThroughput:
        ReadCapacityUnits: 2
        WriteCapacityUnits: 2
      StreamSpecification:
        StreamViewType: NEW_AND_OLD_IMAGES

Outputs:  
  ClientTableStreamArn:
      Description: The ARN for My ClientTable Stream
      Value: !GetAtt ClientTable.StreamArn
      Export:
        Name: my-client-table-stream-arn

serverless.yml

service: my-service

frameworkVersion: ">=1.1.0 <2.0.0"

provider:
  name: aws
  runtime: nodejs6.10
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeStream
        - dynamodb:GetRecords
        - dynamodb:GetShardIterator
        - dynamodb:ListStreams
        - dynamodb:GetItem
        - dynamodb:PutItem
      Resource: arn:aws:dynamodb:*:*:table/client

functions:

  foo:
    handler: foo.main
    events:
      - stream:
          type: dynamodb
          arn: !ImportValue my-client-table-stream-arn
          batchSize: 1

Solution

  • Solved by using ${cf:stackName.outputKey}