aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 77 forks source link

Using a table reference in custom handler causes sandbox deployment to fail #2770

Closed ngmeyer closed 1 month ago

ngmeyer commented 2 months ago

Environment information

System:
  OS: macOS 14.5
  CPU: (8) arm64 Apple M1 Pro
  Memory: 112.25 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 18.17.0 - /usr/local/bin/node
  Yarn: 1.22.19 - /opt/homebrew/bin/yarn
  npm: 10.8.1 - /opt/homebrew/bin/npm
  pnpm: 8.15.1 - /opt/homebrew/bin/pnpm
NPM Packages:
  @aws-amplify/auth-construct: 1.2.0
  @aws-amplify/backend: 1.0.4
  @aws-amplify/backend-auth: 1.1.1
  @aws-amplify/backend-cli: 1.2.2
  @aws-amplify/backend-data: 1.1.0
  @aws-amplify/backend-deployer: 1.0.3
  @aws-amplify/backend-function: 1.3.0
  @aws-amplify/backend-output-schemas: 1.1.0
  @aws-amplify/backend-output-storage: 1.0.2
  @aws-amplify/backend-secret: 1.0.0
  @aws-amplify/backend-storage: 1.0.4
  @aws-amplify/cli-core: 1.1.1
  @aws-amplify/client-config: 1.1.2
  @aws-amplify/deployed-backend-client: 1.2.0
  @aws-amplify/form-generator: 1.0.0
  @aws-amplify/model-generator: 1.0.3
  @aws-amplify/platform-core: 1.0.4
  @aws-amplify/plugin-types: 1.1.0
  @aws-amplify/sandbox: 1.1.1
  @aws-amplify/schema-generator: 1.2.0
  aws-amplify: 6.5.0
  aws-cdk: 2.151.0
  aws-cdk-lib: 2.151.0
  typescript: 5.5.4
AWS environment variables:
  AWS_PROFILE = xyz
  AWS_DEFAULT_REGION = us-east-1
  AWS_REGION = us-east-1
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

During development of a custom handler sandbox development will receive to following error:

The CloudFormation deployment has failed.
Caused By: ❌ Deployment failed: MissingRequiredParameter: Missing required key 'functionId' in params

Resolution: Find more information in the CloudFormation AWS Console for this stack.

This is caused by the usage of a non-hotswapable resource. Extending the general example provided in the documentation

const schema = a.schema({
  Echo: a.model({
    content: a.string(),
    executionDuration: a.float()
  }),

  echo: a
    .query()
    .arguments({ content: a.string() })
    .returns(a.ref('Echo'))
    .authorization(allow => [allow.publicApiKey()])
    .handler(a.handler.custom({
      dataSource: a.ref('Echo'),
        entry: './echo-handler.js'
      });

In this example the dataSource of the Echo Table is not hotswapable, so sandbox deployments while this is set. Workaround whenever modifying this code.

  1. Comment out the dataSource
  2. Save the file so the sandbox deployment proceeds.
  3. Restore the dataSource - sandbox deployment proceeds with the datasource set properly in appSync.
ykethan commented 2 months ago

Hey👋 thanks for raising this! The issue appears to be similar to https://github.com/aws-amplify/amplify-category-api/issues/2307. I'm going to transfer this over to our API repository for better assistance 🙂

AnilMaktala commented 1 month ago

Hey @ngmeyer, This issue has been resolved in https://github.com/aws/aws-cdk/releases/tag/v2.159.0 version. Please upgrade your lib to v2.159 version and let us know the results.

github-actions[bot] commented 1 month ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.