我使用Amplify创建了一个AWS Lambda函数(名为getDictionaryTranslation)。处理程序函数如下:
exports.handler = async function (event, context) { //eslint-disable-line
const appId = process.env.APP_ID;
const appKey = process.env.APP_KEY;
context.done(null, `${appId}|${appKey}`);
};
然后我通过此函数创建了一个GraphQL查询
type Query {
getDictionaryTranslation(word: String!, lang: String!): String! @function(name: "getDictionaryTranslation-${env}")
}
通过遵循本文档https://docs.aws.amazon.com/lambda/latest/dg//env_variables.html
,我们可以在AWS Console上设置APP_ID
和APP_KEY
的值
但是,在我的本地计算机上运行amplify mock
时。如何设置这些变量值?
答案 0 :(得分:1)
我有同样的问题。我有两种解决方法 1.硬编码lambda中的API_KEY,因为键值是一个常量字符串 2.将API_KEY作为环境变量in-cloudformation-template.json添加,并通过相应的function-parameter.json文件传递键值。这种方式也是一种硬编码。