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

AWS Lambda input event is JSON and not string #6216

Open
eladb opened this issue Apr 11, 2024 · 0 comments · May be fixed by #6219
Open

AWS Lambda input event is JSON and not string #6216

eladb opened this issue Apr 11, 2024 · 0 comments · May be fixed by #6219
Labels
☁️ aws Related to Amazon Web Services support 🐛 bug Something isn't working 🎨 sdk SDK

Comments

@eladb
Copy link
Contributor

eladb commented Apr 11, 2024

I tried this:

bring cloud;

let fn = new cloud.Function(inflight (e) => {
  assert(Json.tryParse(e)?.get("foo")?.asNum() == 123);
});

test "send a json object to function" {
  fn.invoke(Json.stringify({ foo: 123 }));
}

This works in the simulator.

Now, deploy to AWS:

wing compile -t tf-aws
cd target/main.tfaws
terraform init
terraform apply

Now, let's try to call invoke this function:

aws lambda invoke --function-name Function-c852aba6 --payload $(echo '{ "foo": 123 }' | base64)  out.json

This happened:

2024-04-11T16:29:33.931Z	ca9e1200-f286-4220-9b6e-f2ca7af93153	ERROR	Invoke Error 	
{
    "errorType": "TypeError",
    "errorMessage": "Cannot read properties of undefined (reading 'foo')",
    "stack": [
        "TypeError: Cannot read properties of undefined (reading 'foo')",
        "    at <anonymous> (/main.w:4:3)",
        "    at $Closure1.handle (/main.w:4:3)",
        "    at Runtime.exports.handler (/var/function_c852aba6.cjs:17:25)",
        "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"
    ]
}

I expected this:

I kind of expected this to work, although I can understand why this doesn't work.

There's a discrepancy between the APIs of Lambda and cloud.Function where cloud.Function handlers are str and at AWS they are JSON values.

Is there a workaround?

No response

Anything else?

I think the right solution on Wing's end is to change the signature of cloud.Function's handle to accept Json? as the input (and output).

This seems like the safest thing to do.

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@eladb eladb added the 🐛 bug Something isn't working label Apr 11, 2024
@eladb eladb changed the title Inflight handler of AWS function AWS Lambda input event is JSON and not string Apr 11, 2024
@staycoolcall911 staycoolcall911 added 🎨 sdk SDK ☁️ aws Related to Amazon Web Services support labels Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☁️ aws Related to Amazon Web Services support 🐛 bug Something isn't working 🎨 sdk SDK
Projects
Status: 🤝 Backlog - handoff to owners
Development

Successfully merging a pull request may close this issue.

2 participants