aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
176 stars 61 forks source link

[Amplify Gen2] passed value from sandbox secret to a function's env always has this literal value `value will be resolved during runtime` #1550

Closed ggj0418 closed 5 months ago

ggj0418 commented 5 months ago

Before opening, please confirm:

JavaScript Framework

Next.js

Amplify APIs

Authentication, REST API, GraphQL API

Amplify Version

v6

Amplify Categories

function

Backend

Amplify Gen 2 (Preview)

Environment information

``` # Put output below this line System: OS: Windows 11 10.0.22631 CPU: (22) x64 Intel(R) Core(TM) Ultra 7 155H Memory: 9.06 GB / 31.53 GB Binaries: Node: 20.11.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD npm: 10.8.0 - ~\WebstormProjects\amplify-next-pages-template\node_modules\.bin\npm.CMD Browsers: Edge: Chromium (123.0.2420.97) Internet Explorer: 11.0.22621.3527 npmPackages: %name%: 0.1.0 @ampproject/toolbox-optimizer: undefined () @aws-amplify/backend: ^1.0.0 => 1.0.2 @aws-amplify/backend-cli: ^1.0.1 => 1.0.3 @aws-amplify/ui-react: ^6.1.7 => 6.1.9 @aws-amplify/ui-react-internal: undefined () @babel/core: undefined () @babel/runtime: 7.22.5 @edge-runtime/cookies: 4.1.0 @edge-runtime/ponyfill: 2.4.2 @edge-runtime/primitives: 4.1.0 @eslint/js: ^9.2.0 => 9.3.0 (8.57.0) @hapi/accept: undefined () @mswjs/interceptors: undefined () @napi-rs/triples: undefined () @next/font: undefined () @next/react-dev-overlay: undefined () @opentelemetry/api: undefined () @svgr/webpack: ^8.1.0 => 8.1.0 @tailwindcss/forms: ^0.5.7 => 0.5.7 @testing-library/react: ^15.0.6 => 15.0.7 @types/node: ^20.12.10 => 20.12.12 @types/react: ^18.3.1 => 18.3.1 @types/react-date-range: ^1.4.9 => 1.4.9 @types/react-dom: ^18.3.0 => 18.3.0 @types/swiper: ^6.0.0 => 6.0.0 @types/uuid: ^9.0.8 => 9.0.8 @vercel/nft: undefined () @vercel/og: 0.6.2 @vitejs/plugin-react: ^4.2.1 => 4.3.0 acorn: undefined () amphtml-validator: undefined () anser: undefined () arg: undefined () assert: undefined () async-retry: undefined () async-sema: undefined () autoprefixer: ^10.4.19 => 10.4.19 aws-amplify: ^6.2.0 => 6.2.0 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/enable-oauth-listener: undefined () aws-amplify/auth/server: undefined () aws-amplify/data: undefined () aws-amplify/data/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () aws-cdk: ^2.140.0 => 2.140.0 aws-cdk-lib: ^2.140.0 => 2.140.0 babel-packages: undefined () browserify-zlib: undefined () browserslist: undefined () buffer: undefined () bytes: undefined () ci-info: undefined () cli-select: undefined () client-only: 0.0.1 comment-json: undefined () compression: undefined () conf: undefined () constants-browserify: undefined () constructs: ^10.3.0 => 10.3.0 content-disposition: undefined () content-type: undefined () cookie: undefined () cross-spawn: undefined () crypto-browserify: undefined () css.escape: undefined () daisyui: ^4.10.5 => 4.11.1 data-uri-to-buffer: undefined () debug: undefined () devalue: undefined () domain-browser: undefined () edge-runtime: undefined () esbuild: ^0.20.2 => 0.20.2 eslint: ^8.57.0 => 8.57.0 eslint-config-prettier: ^9.1.0 => 9.1.0 eslint-plugin-react: ^7.34.1 => 7.34.1 events: undefined () find-cache-dir: undefined () find-up: undefined () fresh: undefined () get-orientation: undefined () glob: undefined () globals: ^15.2.0 => 15.3.0 (11.12.0, 13.24.0) gzip-size: undefined () http-proxy: undefined () http-proxy-agent: undefined () https-browserify: undefined () https-proxy-agent: undefined () icss-utils: undefined () ignore-loader: undefined () image-size: undefined () install: ^0.13.0 => 0.13.0 is-animated: undefined () is-docker: undefined () is-wsl: undefined () jest-worker: undefined () jsdom: ^24.0.0 => 24.0.0 json5: undefined () jsonwebtoken: undefined () loader-runner: undefined () loader-utils: undefined () lodash.curry: undefined () lru-cache: undefined () micromatch: undefined () mini-css-extract-plugin: undefined () nanoid: undefined () native-url: undefined () neo-async: undefined () next: 14.1.4 => 14.1.4 node-fetch: undefined () node-html-parser: undefined () npm: ^10.8.0 => 10.8.0 ora: undefined () os-browserify: undefined () p-limit: undefined () path-browserify: undefined () platform: undefined () postcss: ^8.4.38 => 8.4.38 (8.4.31) postcss-flexbugs-fixes: undefined () postcss-modules-extract-imports: undefined () postcss-modules-local-by-default: undefined () postcss-modules-scope: undefined () postcss-modules-values: undefined () postcss-preset-env: undefined () postcss-safe-parser: undefined () postcss-scss: undefined () postcss-value-parser: undefined () prettier: ^3.2.5 => 3.2.5 (2.3.2, 2.8.8, 1.19.1) prettier-eslint: ^16.3.0 => 16.3.0 process: undefined () punycode: undefined () querystring-es3: undefined () raw-body: undefined () react: ^18 => 18.3.1 react-builtin: undefined () react-dom: ^18 => 18.3.1 react-dom-builtin: undefined () react-dom-experimental-builtin: undefined () react-experimental-builtin: undefined () react-is: 18.2.0 react-refresh: 0.12.0 react-server-dom-turbopack-builtin: undefined () react-server-dom-turbopack-experimental-builtin: undefined () react-server-dom-webpack-builtin: undefined () react-server-dom-webpack-experimental-builtin: undefined () regenerator-runtime: 0.13.4 sass-loader: undefined () scheduler-builtin: undefined () scheduler-experimental-builtin: undefined () schema-utils: undefined () semver: undefined () send: undefined () server-only: 0.0.1 setimmediate: undefined () shell-quote: undefined () source-map: undefined () stacktrace-parser: undefined () stream-browserify: undefined () stream-http: undefined () string-hash: undefined () string_decoder: undefined () strip-ansi: undefined () superstruct: undefined () tailwindcss: ^3.4.3 => 3.4.3 tar: undefined () terser: undefined () text-table: undefined () timers-browserify: undefined () tsx: ^4.9.3 => 4.10.5 tty-browserify: undefined () typescript: ^5.4.5 => 5.4.5 (4.4.4, 4.9.5) typescript-eslint: ^7.9.0 => 7.10.0 ua-parser-js: undefined () unistore: undefined () util: undefined () vitest: ^1.6.0 => 1.6.0 vm-browserify: undefined () watchpack: undefined () web-vitals: undefined () webpack: undefined () webpack-sources: undefined () ws: undefined () zod: undefined () npmGlobalPackages: aws-cdk: 2.126.0 esbuild: 0.20.0 firebase-tools: 13.8.0 node-gyp: 10.1.0 npm-check-updates: 16.14.20 yarn: 1.22.21 ```

Describe the bug

passed value from sandbox secret to a function's env always has this literal value value will be resolved during runtime

Expected behavior

when i check the value sent as a query named testKey on the uri https://example.com/health-check, i expected the query value would be a real value as i set on my sandbox with my profile.

Reproduction steps

  1. you have to have your own aws account having access and secret key (for using sandbox)
  2. clone this repository. it is created with the amplify-nextjs-template. i referenced the amplify gen2 document
  3. install the dependencies with npm
  4. set the sandbox secret with this command npx ampx sandbox secret set NEXT_PUBLIC_TEST_KEY --profile ${USER}. it doesn't matter which value is set
  5. on this path /amplify/functions/test-function/handler.ts, you have to replace the uri with your own one that could receive the request. please check the TODO
  6. create your sandbox environment with this command npx ampx sandbox --profile ${USER} --identifier ${USER}
  7. if you check the created lambda, the api gateway would be there as a trigger. please check that domain and request as a POST method.
  8. when you check the received query value, you would check that value is a literally value will be resolved during runtime

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

ggj0418 commented 5 months ago

I'm sorry for the confusion. the reason of this issue was the npx ampx sandbox secret set command's option parameter.

i set the secret with just a --profile. after that, i created my sandbox environment with --profile and --identifier. so the created secret on the aws parameter store had a different identifier with my sandbox environment.

it was my big mistake. sorry