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

Unable to access site after deployment. #28

Closed
khuezy opened this issue Dec 23, 2022 · 6 comments
Closed

Unable to access site after deployment. #28

khuezy opened this issue Dec 23, 2022 · 6 comments

Comments

@khuezy
Copy link

khuezy commented Dec 23, 2022

Hi, I have a SST + Sveltkit app and deployed it successfully but I'm getting 503:
The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions.

I see in your examples, you have a cdk.json, does that provide some global permissions to the CF + Lambda?

@nbaillie
Copy link

I also see the same error back to the browser from cloudfront, but i can see that the edge function triggers (cloudwatch logs in another region..), is throwing the error bellow:

"errorType": "TypeError",
    "errorMessage": "Cannot read properties of null (reading 'handleError')",
    "stack": [
        "TypeError: Cannot read properties of null (reading 'handleError')",
        "    at Object.handle_error (/var/task/handler.js:27249:35)",
        "    at handle_error_and_jsonify (/var/task/handler.js:25098:20)",
        "    at handle_fatal_error (/var/task/handler.js:25081:22)",
        "    at respond (/var/task/handler.js:27104:18)",
        "    at async Runtime.handler (/var/task/handler.js:27448:20)"
    ]

@khuezy
Copy link
Author

khuezy commented Dec 30, 2022

Yup, thanks for posting that error - I get the same.

@nbaillie
Copy link

@khuezy - after using the adapter with 'yarn build' i edited [my-cdk-folder]/sveltekit/lambda/at-edge/handler.js
just above the line 'log("DEBUG", "render input", input);'
I added the 3 lines you can see bellow, works now.. im sure this is not clean.. and is going to disappear next time i build but working for now so i can have a play.

@juranki - I like the idea with this project. :) Nice work.

const env = {}
log('DEBUG', 'server init with env', env)
await server.init({ env: env })
log("DEBUG", "render input", input);
const rendered = await server.respond(input, {
  getClientAddress() {
    const addrHeader = request.headers["cloudfront-viewer-address"];
    if (addrHeader) {
      return addrHeader[0].value.split(":")[0];
    }
    return "";
  }
});

@juranki
Copy link
Owner

juranki commented Jan 2, 2023

@khuezy , @nbaillie - @sveltekit-cdk/adapter@0.9.1 and @sveltekit-cdk/constructsv2@0.4.0 contain the above fix, and other improvements too. The demo site appears to work, but that's the extent of testing at the moment.

Please try these versions and let me know the results.

@khuezy
Copy link
Author

khuezy commented Jan 2, 2023

Thanks @juranki! I'm able to successfully deploy using the latest versions.
Feel free to close this ticket.

Some questions if I may:

  • Since the handlers are using Lambda@Edge, are there any guidelines when writing APIs? From what I understand, there are some limitations.
  • Does Lambda@Edge support nodejs 18 yet?
  • If using Dynamodb, how do you know the region the Edge function is in to target the closest region?

My VSCode doesn't complain, but when I build:

import { SvelteDistribution } from "@sveltekit-cdk/constructsv2";
         ^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'SvelteDistribution' not found. The requested module '@sveltekit-cdk/constructsv2' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@sveltekit-cdk/constructsv2';
const { SvelteDistribution } = pkg;

@juranki
Copy link
Owner

juranki commented Jan 3, 2023

@khuezy

Would you file an issue about the build error, please? ConstructsV2 builds both esm and commonjs modules. It might be time to drop commonjs.

@khuezy khuezy closed this as completed Jan 3, 2023
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

No branches or pull requests

3 participants