Skip to content
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

How to access SECRETS outside of the "/amplify" directory? #2400

Closed
swbergmann opened this issue Jan 3, 2025 · 1 comment
Closed

How to access SECRETS outside of the "/amplify" directory? #2400

swbergmann opened this issue Jan 3, 2025 · 1 comment
Labels
hosting Issue related to Amplify Hosting

Comments

@swbergmann
Copy link

Environment information

I am using NextJS with Amplify Gen 2 and
- created nextjs application via npx create-next-app myapp
- installed all amplify packages via npm create amplify@latest -y
- started the amplify sandbox via npx ampx sandbox
- set two secrets in the AWS Amplify website: Hosting / Secrets (to be used for all branches)

Nothing special about my environment.

Describe the bug

What works:
If I hard code my secrets into the application code everything works perfectly locally (npm run dev) as well as hosted on AWS Amplify Gen 2 (via the deployed URL). I can confirm perfect functionality of the use case (send emails after submitting a contact form) in all environments.

What does not work:
Accessing/using the secrets (created in the AWS website) is not possible in my application code (outside of the /amplify directory).

I created secrets in the AWS Amplify website and want to use them in my NextJS application in
pages/api/contact.ts
Screenshot 2025-01-02 at 20 38 49

Ideally I want to use the secrets in line #5 and #6 - this is outside of the /amplify directory.

So far I followed the official documentations:
Access Secrets
Set up a Function

My conclusion so far is, that using secrets only works in the /amplify directory i.e.
accessing secret via secret() function in resource.ts
Screenshot 2025-01-03 at 18 09 59

then assigning the secrets via
env from "$amplify/env/secrets"; in the handler.ts
Screenshot 2025-01-03 at 18 10 59

But I am unable to:

  1. import from "$amplify/env/secrets"; in any other directory other than "/amplify" or below
  2. export the values from my secrets so that I can use them in my application files i.e.

Screenshot 2025-01-03 at 18 14 44

Please advise:
How is the intended use of secrets outside the /amplify directory?
Please provide demo code snippets.

Thank you in advance

Reproduction steps

See screenshots attached.

@swbergmann swbergmann added the pending-triage Incoming issues that need categorization label Jan 3, 2025
@ykethan ykethan added the console Issues related to Amplify console UI/UX label Jan 6, 2025
@Jay2113 Jay2113 added hosting Issue related to Amplify Hosting and removed pending-triage Incoming issues that need categorization console Issues related to Amplify console UI/UX labels Jan 6, 2025
@Jay2113
Copy link

Jay2113 commented Jan 6, 2025

Hi @swbergmann 👋 , this thread seems to be a duplicate of #2384. Please refer to my comment here: #2384 (comment).

@Jay2113 Jay2113 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hosting Issue related to Amplify Hosting
Projects
None yet
Development

No branches or pull requests

3 participants