Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow apiKeyAuthorizationMode to be undefined if defaultAuthorizationMode is apiKey #2329

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

dpilch
Copy link
Member

@dpilch dpilch commented Dec 13, 2024

Problem

If defaultAuthorizationMode is set to "apiKey" and apiKeyAuthorizationMode is not defined the deploy will fail with an error. On the data construct side apiKeyConfig is required if defaultAuthorizationMode is API_KEY. The convertAuthorizationModesToCDK should provide apiKeyConfig in this case.

Failed to instantiate data construct
Caused By: Cannot read properties of undefined (reading 'authenticationType')

Resolution: See the underlying error message for more details.
import { type ClientSchema, a, defineData } from "@aws-amplify/backend";

const schema = a.schema({
  Supermarket: a
    .model({
      name: a.string().required(),
      address: a.string(),
    })
    .authorization((allow) => [allow.publicApiKey()]),
});

export type Schema = ClientSchema<typeof schema>;

export const data = defineData({
  schema,
  authorizationModes: {
    defaultAuthorizationMode: "apiKey",
  },
});

Issue number, if available: aws-amplify/amplify-category-api#2994

Changes

Allow apiKeyAuthorizationMode to be undefined if defaultAuthorizationMode is "apiKey".

Corresponding docs PR, if applicable:

Validation

  • Add unit test
  • Test in sample app

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

changeset-bot bot commented Dec 13, 2024

🦋 Changeset detected

Latest commit: c9620e0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@aws-amplify/backend-data Patch
@aws-amplify/backend Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dpilch dpilch changed the title fix: allow apiKeyAuthorizationMode to be undefined if defaultAuthoriz… fix: allow apiKeyAuthorizationMode to be undefined if defaultAuthorizationMode is apiKey Dec 13, 2024
@dpilch dpilch closed this Dec 13, 2024
@dpilch dpilch reopened this Dec 13, 2024
@dpilch dpilch marked this pull request as ready for review December 13, 2024 21:47
@dpilch dpilch requested a review from a team as a code owner December 13, 2024 21:47
@dpilch dpilch enabled auto-merge (squash) December 17, 2024 17:32
@dpilch dpilch merged commit 07fe7d4 into main Dec 17, 2024
79 checks passed
@dpilch dpilch deleted the default-expires branch December 17, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants