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

Customizable Context is needed #502

Open
windymelt opened this issue Aug 6, 2024 · 6 comments
Open

Customizable Context is needed #502

windymelt opened this issue Aug 6, 2024 · 6 comments

Comments

@windymelt
Copy link

windymelt commented Aug 6, 2024

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.

image

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

@armanbilge
Copy link
Member

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?

@windymelt
Copy link
Author

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).

@armanbilge
Copy link
Member

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.

@bpholt
Copy link
Member

bpholt commented Aug 7, 2024

Is this the ClientContext returned by the Context.getClientContext method? https://docs.aws.amazon.com/lambda/latest/dg/java-context.html

@bpholt
Copy link
Member

bpholt commented Aug 7, 2024

I wonder if clientContext.client is undefined on

clientContext.client.installationId,

@armanbilge
Copy link
Member

armanbilge commented Aug 7, 2024

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).

private[lambda] trait ClientContext extends js.Object {
def client: ClientContextClient
def custom: js.UndefOr[js.Any]
def env: ClientContextEnv
}

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