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 code snippet at set-up-function page #8046

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tttol
Copy link

@tttol tttol commented Oct 19, 2024

Description of changes:

When setting up the Lambda function by referring to the “Set up a Function” page, the following error occurred while executing the npx ampx sandbox command.

[Sandbox] Detected file changes while previous deployment was in progress. Invoking 'sandbox' again
File written: amplify_outputs.json
Custom operation sayHello requires both an authorization rule and a handler reference
Caused By: Custom operation sayHello requires both an authorization rule and a handler reference

Resolution: Check your data schema definition for syntax and type errors.

[Sandbox] Watching for file changes...

Page URL: https://docs.amplify.aws/nextjs/build-a-backend/functions/set-up-function/

By adding.authorization(allow => [allow.guest()]) to data/resource.ts, the error was resolved.

  sayHello: a
    .query()
    .arguments({
      name: a.string(),
    })
    .returns(a.string())
    .authorization(allow => [allow.guest()] // Add this line
    .handler(a.handler.function(sayHello)),

I think that the code snippet in the documentation should
be modified, so I created a this PR. If there are any issues with my implementation process and it’s possible to resolve the problem without the line .authorization(allow => [allow.guest()]), could you suggest an alternative solution? I might be saying something incorrect because I’m new to AWS Amplify.

Related GitHub issue #, if available:

Instructions

If this PR should not be merged upon approval for any reason, please submit as a DRAFT

Which product(s) are affected by this PR (if applicable)?

  • amplify-cli
  • amplify-ui
  • amplify-studio
  • amplify-hosting
  • amplify-libraries

Which platform(s) are affected by this PR (if applicable)?

  • JS
  • Swift
  • Android
  • Flutter
  • React Native

Please add the product(s)/platform(s) affected to the PR title

Checks

  • Does this PR conform to the styleguide?

  • Does this PR include filetypes other than markdown or images? Please add or update unit tests accordingly.

  • Are any files being deleted with this PR? If so, have the needed redirects been created?

  • Are all links in MDX files using the MDX link syntax rather than HTML link syntax?

    ref: MDX: [link](https://docs.amplify.aws/)
    HTML: <a href="https://docs.amplify.aws/">link</a>

When this PR is ready to merge, please check the box below

  • Ready to merge

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

@tttol tttol requested a review from a team as a code owner October 19, 2024 23:31
@tttol tttol changed the title Fix code at set-up-function page Fix code snippet at set-up-function page Oct 19, 2024
@tttol
Copy link
Author

tttol commented Oct 31, 2024

@reesscot @swaminator @josefaidt
Could you review this PR? I saw that other users on Discord have also raised the same question, so I think this is a topic of interest for many Amplify users.

@josefaidt josefaidt self-requested a review October 31, 2024 00:58
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.

2 participants