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

feat(aws-lambda): Hono-Lambda Client #3740

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

watany-dev
Copy link
Contributor

When making requests to Lambda behind CloudFront, you may need to implement payload calculation logic as described in the article below.
https://dev.classmethod.jp/articles/cloudfront-lambda-url-with-post-put-request/

This involves unnecessary tedious work, which can be eliminated by wrapping Hono's hc. However, a drawback is that the code becomes quite redundant, so you need to be careful to keep it updated.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 58.18182% with 69 lines in your changes missing coverage. Please review.

Project coverage is 91.20%. Comparing base (47bb23c) to head (f304e9c).

Files with missing lines Patch % Lines
src/adapter/aws-lambda/client.ts 57.92% 69 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3740      +/-   ##
==========================================
- Coverage   91.73%   91.20%   -0.54%     
==========================================
  Files         159      160       +1     
  Lines       10177    10341     +164     
  Branches     2883     2897      +14     
==========================================
+ Hits         9336     9431      +95     
- Misses        840      909      +69     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@watany-dev
Copy link
Contributor Author

watany-dev commented Dec 12, 2024

Alternatively, we might just provide the calculateSHA256 function and implement it like this:

  • case1
import { useOac } from 'hono/lambda'

const client = hc<AppType>('http://localhost:8787/')
const payload = { name: 'Alice', message: 'Hello World' };

// Send POST request
const res = await client.echo.$post(
  {
    json: payload,
  },
  useOac(header),
);
  • case2
import { calculateSHA256 } from 'hono/lambda'

const client = hc<AppType>('http://localhost:8787/')
const payload = { name: 'Alice', message: 'Hello World' };

// Send POST request
const res = await client.echo.$post(
  {
    json: payload,
  },
  {
    headers: {
      'x-amz-content-sha256': await calculateSHA256(JSON.stringify(payload)),
    },
  }
);

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

Successfully merging this pull request may close these issues.

1 participant