From b03225cf76768a74578904343f011347ab3492b2 Mon Sep 17 00:00:00 2001 From: Derek Slenk Date: Fri, 27 Jun 2025 15:51:57 -0400 Subject: [PATCH] Configure Amplify Gen 2 backend with secrets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add secret definition to backend.ts using proper Amplify Gen 2 syntax - Update amplify.yml to include backend build phase - This should properly expose secrets as environment variables 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- amplify.yml | 13 ++++++++----- amplify/backend.ts | 11 +++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/amplify.yml b/amplify.yml index c1facd0..9c464c2 100644 --- a/amplify.yml +++ b/amplify.yml @@ -1,4 +1,10 @@ version: 1 +backend: + phases: + build: + commands: + - npm ci --cache .npm + - npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID frontend: phases: preBuild: @@ -7,11 +13,8 @@ frontend: build: commands: - echo "Build started on `date`" - - echo "Configuring environment variables..." - - echo "YOUTUBE_API_KEY value is ${YOUTUBE_API_KEY}" - - echo "YOUTUBE_API_KEY=${YOUTUBE_API_KEY}" > .env.production - - echo "Contents of .env.production file" - - cat .env.production + - echo "Available environment variables:" + - printenv | grep -E "(YOUTUBE|AMPLIFY)" || echo "No relevant env vars found" - npm run build artifacts: baseDirectory: .next diff --git a/amplify/backend.ts b/amplify/backend.ts index af6aac2..aeab652 100644 --- a/amplify/backend.ts +++ b/amplify/backend.ts @@ -1,11 +1,18 @@ -import { defineBackend } from '@aws-amplify/backend'; +import { defineBackend, secret } from '@aws-amplify/backend'; import { auth } from './auth/resource'; import { data } from './data/resource'; /** * @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more */ -defineBackend({ +const backend = defineBackend({ auth, data, }); + +// Define secrets that will be available as environment variables +backend.addOutput({ + custom: { + YOUTUBE_API_KEY: secret('YOUTUBE_API_KEY'), + }, +});