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

Support handlers that return io.Reader #472

Merged
merged 11 commits into from Dec 23, 2022
Merged

Conversation

bmoffatt
Copy link
Collaborator

Issue #, if available:

#195

Description of changes:

Without this change, to return arbitrary non-json bytes, a user must write something like this

type handler struct{}

func (h *handler) Invoke(_ context.Context, req []byte) ([]byte, error) {
	var name string
	if err := json.Unmarshal(req, &name); err != nil {
		return nil, err
	}
	return []byte("hello " + name), nil
}

func main() {
	lambda.Start(&handler)
}

This works, but isn't perfect:

  1. extra boilerplate to define a type that can implement Invoke
  2. handler is forced to implement it's own unmarshalling of the request

With this change, the above handler can be re-written like:

func main() {
	lambda.Start(func(name string) (io.Reader, error) {
		return strings.NewReader("hello " + name), nil
	})
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2022

Codecov Report

Merging #472 (a6eae08) into main (0f46684) will increase coverage by 1.49%.
The diff coverage is 92.85%.

@@            Coverage Diff             @@
##             main     #472      +/-   ##
==========================================
+ Coverage   69.69%   71.18%   +1.49%     
==========================================
  Files          20       21       +1     
  Lines        1201     1253      +52     
==========================================
+ Hits          837      892      +55     
+ Misses        297      295       -2     
+ Partials       67       66       -1     
Impacted Files Coverage Δ
lambda/entry.go 81.81% <ø> (ø)
lambda/invoke_loop.go 90.17% <83.33%> (+0.75%) ⬆️
lambda/handler.go 95.58% <94.23%> (+3.49%) ⬆️
lambda/runtime_api_client.go 73.13% <100.00%> (ø)
lambda/entry_generic.go 100.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bmoffatt bmoffatt merged commit c80f8ac into aws:main Dec 23, 2022
mergify bot pushed a commit to dbsystel/cdk-sops-secrets that referenced this pull request Jan 9, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/aws/aws-lambda-go](https://togithub.com/aws/aws-lambda-go) | require | minor | `v1.36.1` -> `v1.37.0` |

---

### Release Notes

<details>
<summary>aws/aws-lambda-go</summary>

### [`v1.37.0`](https://togithub.com/aws/aws-lambda-go/releases/tag/v1.37.0)

[Compare Source](https://togithub.com/aws/aws-lambda-go/compare/v1.36.1...v1.37.0)

#### What's Changed

-   Support handlers that return io.Reader by [@&#8203;bmoffatt](https://togithub.com/bmoffatt) in [aws/aws-lambda-go#472
-   Change the executable name in the README examples to `bootstrap` by [@&#8203;bmoffatt](https://togithub.com/bmoffatt) in [aws/aws-lambda-go#476

**Full Changelog**: aws/aws-lambda-go@v1.36.1...v1.37.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/markussiebert/cdk-sops-secrets).
@bmoffatt bmoffatt deleted the io.Reader branch March 25, 2023 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants