问题描述
我正在尝试将 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"
}
}
解决方法
我确实设法解决了这个问题。 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