【问题标题】:Is it possible to dynamically get graphqlEndpoint in a function cloudformation template?是否可以在函数 cloudformation 模板中动态获取 graphqlEndpoint ?
【发布时间】:2021-03-30 14:21:57
【问题描述】:

我正在尝试将 AWS Amplify 生成的 graphqlEndpoint 转换为 Amplify 中的 lambda 函数。目前我在函数的 cloudformation-template.json 中设置了一个环境变量。有没有更好的方法来做到这一点,我错过了?理想情况下,我希望将其动态传递到我的放大函数中,如果 graphqlEndpoint 发生变化,则不必修改每个函数。

我当前在 {LAMBDA-FN-NAME}-cloudformation-template.json 中的静态环境声明如下所示:

"Environment": {
    "Variables": {
            "ENV": {
              "Ref": "env"
            },
            "REGION": {
              "Ref": "AWS::Region"
            },
            "API_{NAME}_GRAPHQLAPIENDPOINTOUTPUT": "https://{ID}.appsync-api.us-east-1.amazonaws.com/graphql"
    }
}

【问题讨论】:

    标签: amazon-cloudformation aws-amplify


    【解决方案1】:

    我确实设法弄清楚了这一点。 Amplify CLI 提供了获取当前 graphql 端点作为 Lambda 内部环境变量的方法。按照这个程序解决了我的问题:

    amplify update function
    Which setting do you want to update? Resource access permissions
    ? Select the category api
    Api category has a resource called X
    ? Select the operations you want to permit for X create, read, update, delete
    
    You can access the following resource attributes as environment variables from your Lambda function
        API_X_GRAPHQLAPIENDPOINTOUTPUT
        API_X_GRAPHQLAPIIDOUTPUT
        API_X_GRAPHQLAPIKEYOUTPUT
    

    【讨论】:

      猜你喜欢
      • 2019-01-20
      • 2019-08-26
      • 2019-08-24
      • 1970-01-01
      • 2017-05-12
      • 2016-10-03
      • 2019-11-22
      • 2012-03-29
      • 2016-03-16
      相关资源
      最近更新 更多