- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
From what I understand, your problem has multiple layers.
Lambda without Proxy Integration
According to the proxy integration documentation, the event object is prepared for you by the proxy integration in the way you said: Set up Lambda proxy integrations in API Gateway.
Without the proxy integration, please consider that the handler gets different content in event
object. This would lead to your problem "throws an error that the parameter is undefined".
So for now let's go with Proxy Integration and see about the CORS Problem.
CORS Problem
A GET
request is considered a "simple request" in matters of CORS. I found the MDN documentation about CORS very helpful (read from top to bottom once, totally took away the "magic appearance" from CORS): MDN Cross-Origin Resource Sharing (CORS).
Your HTTP response must contain an Allow-Control-Allow-Origin
HTTP Header. AWS Documentation should give you more directions: Enabling CORS support for proxy integrations.
export const handler = async (event) => { const response = { statusCode: 200, headers: { "Access-Control-Allow-Headers" : "Content-Type", "Access-Control-Allow-Origin": "https://www.example.com", "Access-Control-Allow-Methods": "OPTIONS,POST,GET" }, body: JSON.stringify('Hello from Lambda!'), }; return response; };
I hope this can somewhat shed some light on your situation!
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor einem Jahr
- AWS OFFICIALAktualisiert vor einem Jahr
- AWS OFFICIALAktualisiert vor 2 Jahren
Thank you. this worked for me. I had to add the "Access-Control-Allow-Origin" to the header object in the response returned. Then I easily used the function with Lambda proxy integration without having to worry about mapping or templating.
Awesome! Happy I could help!
Hey jay, one more thing. Since the answer was working for you, I would kindly ask you to mark it as "Accepted answer" if possible. :-)