Customizable Context is needed
I wrote AWS Lambda handler using Feral IOLambda.Simple to handle IoT device (not Amazon IoT Button, but SORACOM's one) click event.
Since my IoT provider directly invokes lambda, lambda receives completely different Context from environment (for example it contains simId field). Thus runtime throws Cannot read properties of undefined (reading 'installationId') when decoding Context. When I invoke the lambda manually, the error does not occur.
Unfortunately, I cannot avoid this bahavior because decoding Context is completely untouchable.
In my use-case I don't need Context but input.
Would you mind to make Context type overridable and fully customizable?
Appendix
For example SORACOM's context is described here: https://users.soracom.io/ja-jp/docs/funk/format/#nodejs-%E3%83%A9%E3%83%B3%E3%82%BF%E3%82%A4%E3%83%A0%E3%81%AE%E5%A0%B4%E5%90%88
Since my IoT provider directly invokes lambda
Huh, can you explain more about what this means? Does it mean your lambda is not hosted on AWS servers at all?
Sorry, my wording wasn't clear enough. Lambdas are hosted on my account on AWS servers as usual. I meant that lambdas aren't invoked through AWS API Gateway. It is invoked across my AWS account and provider account (by attaching policy).
I see, thanks for clarifying 🤔 is there any documentation about this? How do the official AWS Lambda libraries support custom contexts? On JVM and JS Feral is just a wrapper around the official libraries.
Is this the ClientContext returned by the Context.getClientContext method? https://docs.aws.amazon.com/lambda/latest/dg/java-context.html
I wonder if clientContext.client is undefined on https://github.com/typelevel/feral/blob/07b05570ee86ce1cfdd4204c94338ec0bb1de722/lambda/js/src/main/scala/feral/lambda/ContextPlatform.scala#L45
Yes, thanks, I think you're right! We probably need to model client as an UndefOr in the facade. (Also it looks like there is a field for custom properties as well).
https://github.com/typelevel/feral/blob/07b05570ee86ce1cfdd4204c94338ec0bb1de722/lambda/js/src/main/scala/feral/lambda/facade/Context.scala#L39-L43
It's frustrating that the Typescript definitions for this type don't model this as potentially undefined:
export interface ClientContext {
client: ClientContextClient;
Custom?: any;
env: ClientContextEnv;
}
I'm going to open a PR with a proposal to make this work, although it's a little ugly due to bincompat concerns. (We can discuss that in the PR comments.)