2017-09-01 49 views
1

我正嘗試從CloudFormation中創建的堆棧中導出DynamoDb StreamArn,然後使用serverless.yml中的!ImportValue引用導出。!無服務器框架中的ImportValue不起作用

但我收到此錯誤信息:

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

的cloudformation和serverless.yml定義如下。任何幫助讚賞。

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 

回答

1

解決使用${cf:stackName.outputKey}

+0

你也可以在無服務器YAML文件中使用的參考值導出: FN :: ImportValue:我的客戶端表流,阿爾恩 – Metallikanz

2

看來,您使用的!ImportValue簡寫CloudFormation YAML。我的理解是,當CloudFormation解析YAML時,!ImportValue實際上是別名Fn::ImportValue。根據無服務器功能文檔,它似乎應該支持導入的Fn::ImportValue形式。

基於對Fn::ImportValue的文檔,你應該能夠引用您的出口就像

- stream: 
     type: dynamodb 
     arn: {"Fn::ImportValue": "my-client-table-stream-arn"} 
     batchSize: 1 

希望幫助您解決問題。