-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document function environment variables and secrets #1052
Comments
Hi @FirstSanny, the Can you explain more about where you are trying to use the secrets and what your use case is? |
Hello @edwardfoyle , thanks for your reply. Currently this class is defined in the amplify/clients folder and will be globally assigned to an default instance like this: The issue came, when using this instance, but is it called inside of an defineFunction context. The finction is getting exported with the data export of the resource.ts We can try to fetch the credentials inside of the handler function and pass them to the instance from there. Do you think this would work? |
@FirstSanny thanks for the additional context. The way you would do this is to define a secret environment variable in your function like so: defineFunction({
entry: './some/path.ts',
environment: {
SHOPIFY_API_KEY: secret('SHOPIFY_API_KEY')
}
}) Then in your function code, you can use export const handler = async () => {
process.env.SHOPIFY_API_KEY // this will be the value of the API key when the lambda runs
} We need to update our docs to describe this new behavior! |
That worked. Thanks. |
@edwardfoyle I'm trying something similar, but I want to access the secrets inside the Next.js API routes. Is there any easy way to do that? I imagine I can rewrite it as a Function fronted by an API Gateway and follow your example above, but hoping for a simpler solution. |
Hey @chucklam you can manage secrets for branches from the Amplify console then you can |
Is it supposed to work within the sandbox? I am using npx amplify sandbox secret XXXX to configure my secret but it only works when I deploy the branch. Thanks. |
I have set the secrets from the Amplify console. Not clear to me how to build:
commands:
- echo "NEXTAUTH_SECRET=$NEXTAUTH_SECRET" >> .env
- npm run build |
Hey @chucklam, @josefaidt I have defined the secrets in the amplify console: And then I try to read the secrets and write them to a dotenv file build:
commands:
- echo "KEYCLOAK_SECRET=$(echo $secrets | jq -r '.KEYCLOAK_SECRET')" >> .env But if I look at the .env file the I get just Do you have any solution for this in the meantime? Many thanks and regards, |
@bnova-stefan @josefaidt In fact if I just look at
|
|
Did anyone get the echo secrets to a .env file to work? |
If you look at Amplify build logs, you will see log line like this:
However, what's even more confusing, if you configure secrets through AWS Amplify Gen2 console as mentioned in the documentation1. It actually creates Parameters by path like Also, see this super helpful comment: Footnotes |
Environment information
Description
The secrets arent getting loaded into my app. It works if I just hardcode them (thats how I figured, it's something about the secrets). It is also worth to mention, that if I wouldn't double cast them, typescript would throw an error, because it is recognising it as an object of type
BackendSecret
.This is the code:
I added for alle branches and my sandbox. But no luck...

The text was updated successfully, but these errors were encountered: