I created an AWS Lambda function (named getDictionaryTranslation) with Amplify. The handler function look like:
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}`);
};
Then I created a GraphQL Query from this function
type Query {
getDictionaryTranslation(word: String!, lang: String!): String! @function(name: "getDictionaryTranslation-${env}")
}
We can set APP_ID and APP_KEY value on AWS Console by following this document https://docs.aws.amazon.com/lambda/latest/dg//env_variables.html
However, when running amplify mock in my local machine. How can I set these variables values?
just create and store your .env variable on the root path of your function:
amplify/backend/function/<function name>/.env
So in your case:
amplify/backend/function/getDictionaryTranslation/.env
That will overwrite the env variables you added with the CLI and allow you to configure any runtime env variables for amplify mock, which also means in that .env file you need to have all the variables you set using the CLI for that specific cloud function.
More details on the doc: Function mock environment variables
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With