嵌套堆栈无法使用RequestMappingTemplateS3Loc​​ation检测模板中的更改 [英] Nested stack does not detect changes in the template with RequestMappingTemplateS3Location

查看:40
本文介绍了嵌套堆栈无法使用RequestMappingTemplateS3Loc​​ation检测模板中的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有嵌套堆栈的无服务器规范,我想使用RequestMappingTemplateS3Loc​​ation和ResponseMappingTemplateS3Loc​​ation定义Type:AWS :: AppSync :: Resolver,并且模板位于s3中.当我更新模板时,堆栈不会更新cloudformation.

 资源:AppSyncResolverTestStack:类型:AWS :: CloudFormation :: Stack依赖于取决于:-GraphQlApi-GraphQlSchema特性:参数:MappingTemplatesURL:Fn ::加入:-"/"--"s3:/"-$ {self:provider.deploymentBucket}- 'ETC'-$ {opt:stage}-'mapping_templates_extra'GraphQlApiId:Fn :: GetAtt:-GraphQlApi-ApiIdTemplateURL:Fn ::加入:-"/"--"https://s3.amazonaws.com"-$ {self:provider.deploymentBucket}- 'ETC'-$ {opt:stage}-'cf-resolvers-2.yml' 

嵌套

 参数:MappingTemplatesURL:类型:字符串GraphQlApiId:类型:字符串资源:FCSYSAPIGraphQlResolverFinancialRequest:类型:AWS :: AppSync :: Resolver特性:别名:参考:GraphQlApiId类型名称:突变栏位名称:FinanceDocumentsApiDataSourceName:"FCFinanceApi"RequestMappingTemplateS3Loc​​ation:Fn ::加入:-"/"--参考:MappingTemplatesURL-"fc-finance"-"FinanceDocuments.request.vm"ResponseMappingTemplateS3Loc​​ation:Fn ::加入:-"/"--参考:MappingTemplatesURL-"fc-finance"-"FinanceDocuments.response.vm" 

我希望当我在s3中更新模板并部署我的项目时,cloudformation会被更新,但是它会与以前的代码一起维护.

解决方案

这是CloudFormation的正常行为.CloudFormation 仅在资源属性更改时更新资源.

由于属性 RequestMappingTemplateS3Loc​​ation ResponseMappingTemplateS3Loc​​ation 不变,因此CloudFormation不会更新您的AppSync解析器(即使这些S3位置指向新"内容)./p>

解决问题的一种方法是使用 aws cloudformation package 命令.它允许您使用本地文件定义模板:

 类型:"AWS :: AppSync :: Resolver"特性:...RequestMappingTemplateS3Loc​​ation:'./path/to/local/template/file'... 

运行

  aws cloudformation软件包--template-file mytemplate.yml --s3-bucket mybucket --output-template-file packaged.template 

返回模板的副本( packaged.template ),并用命令上载工件的S3位置替换对本地工件的引用.S3位置名称(键)取决于内容(使用MD5).因此,使用这种策略,如果S3位置引用的内容发生更改,则属性 RequestMappingTemplateS3Loc​​ation 也会更改.

之后,您可以使用部署模板 aws cloudformation部署 .

注意:这与使用 AWS SAM CLI sam包 aws cloudformation包

的别名

如果使用无服务器框架,另一种解决方案是使用 serverless-appsync-plugin 允许内联或在文件中指定映射模板.

I have a serverless specification with a nested stack, I want to define Type: AWS :: AppSync :: Resolver using RequestMappingTemplateS3Location and ResponseMappingTemplateS3Location, and the templates are in s3. When I update the template the stack does not update the cloudformation.

 Resource:
    AppSyncResolverTestStack:
      Type: AWS::CloudFormation::Stack
      DependsOn:
        - GraphQlApi
        - GraphQlSchema
      Properties:
        Parameters:
          MappingTemplatesURL:
            Fn::Join:
              - "/"
              - - "s3:/"
                - ${self:provider.deploymentBucket}
                - 'etc'
                - ${opt:stage}
                - 'mapping_templates_extra'
          GraphQlApiId:
            Fn::GetAtt:
              - GraphQlApi
              - ApiId
        TemplateURL:
          Fn::Join:
            - "/"
            - - "https://s3.amazonaws.com"
              - ${self:provider.deploymentBucket}
              - 'etc'
              - ${opt:stage}
              - 'cf-resolvers-2.yml'

Nested

Parameters:
  MappingTemplatesURL:
    Type: String
  GraphQlApiId:
    Type: String
Resources:
  FCSYSAPIGraphQlResolverFinancialRequest:
    Type: AWS::AppSync::Resolver
    Properties:
      ApiId:
        Ref: GraphQlApiId
      TypeName: Mutation
      FieldName: FinanceDocumentsApi
      DataSourceName: "FCFinanceApi"
      RequestMappingTemplateS3Location:
        Fn::Join:
          - "/"
          - - Ref: MappingTemplatesURL
            - "fc-finance"
            - "FinanceDocuments.request.vm"
      ResponseMappingTemplateS3Location:
        Fn::Join:
          - "/"
          - - Ref: MappingTemplatesURL
            - "fc-finance"
            - "FinanceDocuments.response.vm"

I expect that when I update the template in s3 and deploy my project the cloudformation is updated, but it is maintained with the previous code.

解决方案

This is the normal behavior of CloudFormation. CloudFormation only updates a resource when its properties change.

Since the properties RequestMappingTemplateS3Location and ResponseMappingTemplateS3Location do not change, CloudFormation doesn't update your AppSync Resolver (even though those S3 locations points to "new" content).

One way to solve your problem is to use the aws cloudformation package command of the AWS CLI. It allows you to define your template with local files:

Type: 'AWS::AppSync::Resolver'
Properties:
  ...
  RequestMappingTemplateS3Location: './path/to/local/template/file'
  ...

Running

aws cloudformation package --template-file mytemplate.yml --s3-bucket mybucket --output-template-file packaged.template

returns a copy of your template (packaged.template), replacing references to local artifacts with the S3 location where the command uploaded the artifacts. The S3 location name (key) depends on the content (uses MD5). Hence, with this strategy, the property RequestMappingTemplateS3Location changes if the content referenced by the S3 location changes.

After that, you can deploy your template with aws cloudformation deploy.

Note: this is the same as using AWS SAM CLI, sam package is an alias of aws cloudformation package

If working with the serverless framework, another solution is to use the serverless-appsync-plugin which allows to specify mapping templates inline or in a file.

这篇关于嵌套堆栈无法使用RequestMappingTemplateS3Loc​​ation检测模板中的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆