Open jbarwick opened 6 years ago
@jbarwick Did you manage to fix this and get CORS working with your MH project?
I don’t think so. I didn’t do anything specific. I am ignoring the console. If it works, I’m leaving it alone. And it seems to be working. Whatever the setting. I will check and post later
I'm having the same issue. Although in trying to disable / enable cloud-api, my app is now in a bad state. When I do an awsmobile push, CloudFormation is rolling back every single time. The CREATE_FAILED status reason is that the embedded stack wasn't created - one of the resources failed to create. I'm going to back all the way up and try again.
Quick update - disabled cloud-api, made sure to delete all artifacts from Lambda console, CloudFormation, etc. Pulled. Re-enabled. Pushed. Now I'm back in business and CORS is working by default. Not sure what happened, but happy to be back on track!
@tlpierce: Sorry to hear about your issue with the 'cloud-api' feature. AWS Mobile Hub does not delete your Lambda functions when you disable the cloud-api feature via the CLI/console. This is why you were unable to redeploy the stack when you made changes. As you realized, once you deleted the Lambdas, you were back in business. Let me know if you have any other issues.
@jbarwick: Really sorry to hear about your issue and thanks for suggesting a workaround. While we investigate this issue, the workaround for now is to enable CORS via the CLI and not modify it via the console.
I've been struggling with this issue since monday, really taking up my time at work. I've gathered some questions if you could be of help @swaminator 💯
awsmobile --version >>> 1.1.5
First off, my issues:
custom_header: async () => { return {Authorization: (await Auth.currentSession()).idToken.jwtToken}}
which is supposed to append an Authorization token. Authorization: None and API Key: Not required
. This also doesn't make sense to me, because Auth is actually required. => Now I'm getting 403 error, which I bypassed yesterday my making sure Authorization: NoneAuthorization: AWS_IAM and API Key: Not required
, and it also adds a Mock Endpoint for CORS. Perfect.Some questions then
403
unless it's Public and I can't update to Public in MobileHub console without deleting my Lambda and removing Mock Endpoint CORS in Gateway. Feature request: Replace requires-signin with "authorization": "private/public/protected".
I hope this wasn't too much text, but I've been struggling for ~20-30 hours with this. I love the MobileHub product, but might start looking into the new amplify-cli as I'd like to avoid unsynced consoles!
Thanks anyways, hope this helps debugging from your side. Cheers!
I can confirm at least that when I setup a cloud api and choose cors in the console it does not work. I've been beating my head on this for too long. How does anyone build things with this being so difficult?
Failed to load https://ootbx5nkea.execute-api.us-west-2.amazonaws.com/Development/items: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
I tried deleting all artifacts as well and then with the yml option set for cors pushed. The push was nominal however I am still not getting CORS enabled endpoints.
I don't understand how anything built on top this would not depend on CORS, you would have to have something on the same domain/subdomain if I understand correctly and I can't think of a single use case where this would be useful without CORS.
Is it possible for you all to report this issue of the console not setting up CORS to the appropriate AWS team? I'm relatively new to aws mobile hub and related tooling but this has been a pretty bad DX. Cognito with aws-amplify-react was so smooth it sucked me into adopting aws mobile as well.
For what it's worth the CORS setting does not work even if you create a new API in the console and do not use awsmobile-cli at all. IMHO that's a showstopper and should be addressed as such.
@jamesporter, sometimes the issue is not CORS (even if the error said so), when you look on the network requests you should see 2 HTTP request: one for OPTIONS method and the second for the method you are trying to call. Do you have OPTIONS request with a server error?
For what it's worth the CORS setting does not work even if you create a new API in the console and do not use awsmobile-cli at all. IMHO that's a showstopper and should be addressed as such.
All of that said, I can't seem to get this to be properly automated by Mobile Hub. If this was a one-and-done process, then I could forget about it. However, it is unacceptable since all of this is undone whenever I run awsmobile publish from the CLI. Are there any hidden steps for enabling CORS from Mobile Hub? I don't know how much of the following is relevant, but these are all of my settings as reflected in Mobile Hub:
Based on @Jeyloh 's response, it looks like I may be able to update my .yml file, but I'd prefer to avoid that as I've already run into some hairy issues by manually updating files.
I have an API defined in mobile-hub-project.yml such as this:
commentsCRUD: !com.amazonaws.mobilehub.v0.API attributes: name: commentsCRUD requires-signin: true sdk-generation-stage-name: Development
paths: /comments: !com.amazonaws.mobilehub.v0.Function codeFilename: uploads/comments-20180706221653.zip description: 'Handler for calls to resource path : /comments/{proxy+}' enableCORS: true environment: {} handler: lambda.handler
CORS is said to be enabled.
The Mobile Hub Console indicates CORS as "disabled" (the checkbox is clear, which I would assume means the console feels the CORS is disable).
When clicking the checkbox to enable CORS on the console, and after the stack is updated, and I do an awsmobile pull, the handler: is set to "handler: index.handler", there is a brand new file called index.js inserted into the source code with a generic template, and the enableCORS:true is removed from the yml file.
Then, the frontend responds with a "failed preflight check" and "network error" from Amplify API.
The only way to fix this was to delete the entire API stack from cloudformation, disable and re-enable the cloud-api from awsmbile-cli and restart all API from scratch.
Has anyone ever had this same experience?