首页 > 解决方案 > AWS SAM 本地启动 API 无法解析 Fn::ImportValue

问题描述

我有 SAM 模板(部分张贴在这里):

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

Parameters:

  StorageStackName:
    Type: String
    Description: Name of the stack which provisions DynamoDB table and S3 bucket.

Globals:

  Function:
      Runtime: nodejs12.x
      MemorySize: 128
      Timeout: 8
      CodeUri: .
      AutoPublishAlias: latest
      Environment:
        Variables:
          SOURCE_TABLE_NAME:
            Fn::ImportValue:
              Fn::Sub: "${StorageStackName}-SourceTableName"

命令给我一个通知

sam local start-api --debug --parameter-overrides='StorageStackName=storage-dev'

Unable to resolve property SOURCE_TABLE_NAME: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${StorageStackName}-SourceTableName')]))]). Leaving as is.

我试图删除 Sub(不走运):

SOURCE_TABLE_NAME:
  Fn::ImportValue: "storage-dev-SourceTableName"

该模板在服务器上工作,因此支持 Fn::ImportValue。所以我的问题是本地调用完全支持 Fn::ImportValue 吗?

storage-dev我确保我使用与我拥有堆栈的本地 SAM 相同的凭据(配置文件) 。有什么办法可以再次检查以确保更多?

标签: amazon-web-servicesaws-samserverless-application-model

解决方案


从这篇文章开始,它似乎不受支持。我能找到的最后一个PR 只包括 !Sub 和 !If。看起来它们必须在 sam cli 成熟时作为参数或环境变量传入。


推荐阅读