Amplify Build using Secrets Manager

Viewed 33

I am trying to access my Secret Manager values as environment variables in the build of my Amplify application.

I have followed AWS documentation and community threads/videos.

I have included in my build spec file, amplify.yml, as below per the guide: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-versions

version: 1
env:
  secrets-manager:
    TOKEN: mySecret:myKey
    
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - echo "$TOKEN"
        - yarn run build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - .next/cache/**/*

I have attached Secret Manager access policies to my Amplify service role per community threads and this YouTube video:

https://youtu.be/jSY7Xerc8-s

However, echo $TOKEN returns blank

Is there no way to access Secret Manager key-values in the Amplify build settings (https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html) like you can just the same in Code Build (see above guide)?

So far I have only been able to store my sensitive enviroment variables with Parameter Store (following this guide: https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html) but from my understanding does seem secure as the values are displayed when echo is used, which will be exposed during logs, whereas values from Secret Manager with be censored out as '***'.

0 Answers
Related