Describe the bug
Following the https://docs.amplify.aws/cli/function#query, it used:
headers: {
'x-api-key': process.env.API_KEY
}
To Reproduce
Steps to reproduce the behavior:
{ allow: public, provider: apiKey }process.env and you'll see that API_KEY is not there.Expected behavior
Should API_KEY be there or not?
Code Snippet
Just follow steps above.
Screenshots
If applicable, add screenshots to help explain your problem.
What is Configured?
If applicable, please provide what is configured for Amplify CLI:
aws-exports file:
const awsmobile = {
"aws_project_region": "us-east-1",
"aws_cognito_identity_pool_id": "us-east-1:xxx-xxxx-xxxx-xxxx-xxxxxxxx",
"aws_cognito_region": "us-east-1",
"aws_user_pools_id": "us-east-1_xxx",
"aws_user_pools_web_client_id": "xxxx",
"oauth": {}
};
{
Auth: {
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
region: 'XX-XXXX-X',
identityPoolRegion: 'XX-XXXX-X',
userPoolId: 'XX-XXXX-X_abcd1234',
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
mandatorySignIn: false,
authenticationFlowType: 'USER_PASSWORD_AUTH',
oauth: {
domain: 'your_cognito_domain',
scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
redirectSignIn: 'http://localhost:3000/',
redirectSignOut: 'http://localhost:3000/',
responseType: 'code' // or 'token', note that REFRESH token will only be generated when the responseType is code
}
}
}
aws cognito-idp describe-user-pool --user-pool-id us-west-2_xxxxxx (Be sure to remove any sensitive data)
Environment
npx envinfo --system --binaries --browsers --npmPackages --npmGlobalPackages
Smartphone (please complete the following information):
Additional context
I'm trying to do this:
// somewhere above
const { GraphQLClient } = require('graphql-request');
// inside handler
const client = new GraphQLClient(
endpoint,
{
headers: {
'x-api-key': process.env.API_KEY
}
}
);
_You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app._
I saw this but unsure if related, since it talked about mock. https://github.com/aws-amplify/amplify-cli/issues/3124
Transferring to CLI
I reproduced the bug.
We will work on a fix soon.
In the meanwhile, you can manually add the environment variable to the Lambda Function to unblock your work.
amplify function console. Environment variables section and click on EditAdd environment variableYou can find the ApiKey from the amplify/backend/amplify-meta.json file, it's in the output of the api resource: api.<api-name>/output/GraphQLAPIKeyOutput
@aprilmintacpineda The fix for this has been released in CLI v 4.26.0. The environment variable will be populated in API_
Most helpful comment
@aprilmintacpineda The fix for this has been released in CLI v 4.26.0. The environment variable will be populated in API__GRAPHQLAPIKEYOUTPUT. I have a docs PR above to update the docs to the new env variable as well.