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
184 stars 62 forks source link

Amplify Outputs dart file containing undefined variable in config string #2173

Closed ekjotmultani closed 1 week ago

ekjotmultani commented 2 weeks ago

Environment information

System:
  OS: macOS 14.7
  CPU: (12) arm64 Apple M3 Pro
  Memory: 304.31 MB / 36.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 22.8.0 - /opt/homebrew/bin/node
  Yarn: undefined - undefined
  npm: 10.8.2 - /opt/homebrew/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.3.2
  @aws-amplify/backend: 1.5.2
  @aws-amplify/backend-auth: 1.2.0
  @aws-amplify/backend-cli: 1.3.0
  @aws-amplify/backend-data: 1.1.5
  @aws-amplify/backend-deployer: 1.1.5
  @aws-amplify/backend-function: 1.7.2
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.2
  @aws-amplify/backend-secret: 1.1.4
  @aws-amplify/backend-storage: 1.2.1
  @aws-amplify/cli-core: 1.1.3
  @aws-amplify/client-config: 1.5.0
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.8
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.3.0
  @aws-amplify/sandbox: 1.2.3
  @aws-amplify/schema-generator: 1.2.4
  aws-amplify: 6.7.0
  aws-cdk: 2.164.1
  aws-cdk-lib: 2.164.1
  typescript: 5.6.3
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the bug

After running npx ampx --outputs-format dart --outputs-out-dir lib with this Storage definition, the resulting amplify_outputs.dart file contains the entity variable "cognito-identity.amazonaws.com:sub" from the access specification in the path from the definition. This is a syntax error and invalidates the backend. The faulty part of the outputs file looks like:

...
"buckets": [
      {
        "name": "amplifyTeamDrive",
        "bucket_name": "amplify-customer-ekjotm-s-amplifyteamdrivebucket28-lamxahg5tb0t",
        "aws_region": "us-east-1",
        "paths": {
          "profile-pictures/*": {
            "guest": [
              "get",
              "list"
            ]
          },
          "profile-pictures/${cognito-identity.amazonaws.com:sub}/*": {
            "entityidentity": [
              "get",
              "list",
              "write",
              "delete"
            ]
          },
         ...

Reproduction steps

  1. Spin up a gen 2 app
  2. Add the following storage definition:
    name: 'amplifyTeamDrive',
    access: (allow) => ({
    'profile-pictures/{entity_id}/*': [
      allow.guest.to(['read']),
      allow.entity('identity').to(['read', 'write', 'delete'])
    ],
    'picture-submissions/*': [
      allow.authenticated.to(['read','write']),
      allow.guest.to(['read', 'write'])
    ],
    })
    });
  3. run npx ampx sandbox --outputs-format dart --outputs-out-dir lib
  4. the resulting amplify_outputs.dart file will have the error
ykethan commented 2 weeks ago

Marking as bug