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

Schematize lambda.CallbackFunction overlay and add docs for it #4352

Merged
merged 5 commits into from
Aug 8, 2024

Conversation

flostadler
Copy link
Contributor

The CallbackFunction resource overlay was not present in the registry before. This change adds the schema for it and adds the docs for the registry.
The schema is mostly based on the lambda.Function resource with modifications to adhere to the typescript class here:

export interface CallbackFunctionArgs<E, R> extends BaseCallbackFunctionArgs {

How to review?

Fixes #4351

The CallbackFunction resource overlay was not present in the registry
before. This change adds the schema for it and adds the docs for the
registry.
@flostadler flostadler requested review from t0yv0, corymhall and a team August 7, 2024 18:07
@flostadler flostadler self-assigned this Aug 7, 2024
)

// extraTypes augment the types defined by the upstream AWS provider
var extraTypes = map[string]schema.ComplexTypeSpec{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this to its own file to make it easier to work with and add additional extraTypes sources (like the overlays)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much, I dread working in the super long resources.go.

TypeSpec: schema.TypeSpec{
Ref: "#/types/aws:lambda/Runtime:Runtime",
},
Description: "The Lambda runtime to use. If not provided, will default to `NodeJS20dX`.",
Copy link
Contributor Author

@flostadler flostadler Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true yet, but we're currently updating it here: #4348

This PR will only go in after that one

Copy link

github-actions bot commented Aug 7, 2024

Does the PR have any schema changes?

Looking good! No breaking changes found.

New resources:

  • lambda/callbackFunction.CallbackFunction

Maintainer note: consult the runbook for dealing with any breaking changes.

// typeOverlays augment the types defined by the upstream AWS provider
var typeOverlays = map[string]schema.ComplexTypeSpec{}

//go:embed pkg/overlays/examples/callbackFunction.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a moot point for just one file but if we're doing it a lot we can avoid shipping this into pulumi-resource-aws binary to avoid bulking it up. Trouble with resources.go code is that it's evaluated twice, once for tfgen and once for runtime startup in the provider, so it's a little tricky, but can be done with os.ReadFile that only runs for make tfgen case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should opt for the simpler option here to avoid bugs and trouble down the road. Even if we had multiple files it wouldn't be a lot of storage size we're adding. The markdown file for the callbackFunction has ~9KB, so we'd need a lot of them before this has meaningful impact on the overall size of the provider (~794MB right now).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I concede the point.. The provider binary is too large but we need to look holistically as to what to do with that, this is not really the root problem here.

You can provide the JavaScript function used for the Lambda Function's Handler either directly by setting the `callback` input property or instead specify the `callbackFactory`, which is a Javascript function that will be called to produce the callback function that is the entrypoint for the AWS Lambda.
Using `callbackFactory` is useful when there is expensive initialization work that should only be executed once. The factory-function will be invoked once when the final AWS Lambda module is loaded. It can run whatever code it needs, and will end by returning the actual function that Lambda will call into each time the Lambda is invoked.

The callback function should follow the following signature: `(event: E, context: Context, callback: (error?: Error | string | null, result?: R) => void) => Promise<R> | void`. It is recommended to use an async function, otherwise the Lambda execution will run until the `callback` parameter is called and the event loop is empty. See [Define Lambda function handler in Node.js](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html) for additional details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider avoiding inline code gory details in favor of a code example (or just entirely drop).


See [Function Serialization](https://www.pulumi.com/docs/concepts/inputs-outputs/function-serialization/) for additional details on this process.

If no IAM Role is specified, CallbackFunction will automatically use the following managed policies:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this important information to have upfront, or perhaps reference section at the bottom?


Notice the path to the file is now `/opt/config/config.json` --- `/opt` being the path at which AWS Lambda extracts the contents of a layer. The configuration layer is now manageable and deployable independently of the Lambda itself, allowing changes to be applied immediately across all functions that use it.

#### Using layers for Node.js dependencies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, very nice.

Copy link
Member

@t0yv0 t0yv0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

@flostadler flostadler requested a review from t0yv0 August 8, 2024 16:45
@flostadler flostadler enabled auto-merge (squash) August 8, 2024 17:52
@flostadler flostadler merged commit 8f1755f into master Aug 8, 2024
30 checks passed
@flostadler flostadler deleted the flostadler/callback-function-overlay-docs branch August 8, 2024 17:54
lumiere-bot bot added a commit to coolguy1771/home-ops that referenced this pull request Aug 14, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@pulumi/aws](https://pulumi.io)
([source](https://togithub.com/pulumi/pulumi-aws)) | dependencies |
minor | [`6.48.0` ->
`6.49.0`](https://renovatebot.com/diffs/npm/@pulumi%2faws/6.48.0/6.49.0)
|

---

### Release Notes

<details>
<summary>pulumi/pulumi-aws (@&#8203;pulumi/aws)</summary>

###
[`v6.49.0`](https://togithub.com/pulumi/pulumi-aws/releases/tag/v6.49.0)

[Compare
Source](https://togithub.com/pulumi/pulumi-aws/compare/v6.48.0...v6.49.0)

##### Does the PR have any schema changes?

Looking good! No breaking changes found.

##### New resources:

-   `ebs/snapshotBlockPublicAccess.SnapshotBlockPublicAccess`
-   `lambda/callbackFunction.CallbackFunction`
-   `rds/integration.Integration`

##### New functions:

-   `rds/getClusterParameterGroup.getClusterParameterGroup`
-   `secretsmanager/getSecretVersions.getSecretVersions`

##### What's Changed

- Update GitHub Actions workflows. by
[@&#8203;pulumi-bot](https://togithub.com/pulumi-bot) in
[pulumi/pulumi-aws#4353
- Upgrade CallbackFunction default runtime to Node 20.x by
[@&#8203;t0yv0](https://togithub.com/t0yv0) in
[pulumi/pulumi-aws#4348
- Schematize lambda.CallbackFunction overlay and add docs for it by
[@&#8203;flostadler](https://togithub.com/flostadler) in
[pulumi/pulumi-aws#4352
- Upgrade terraform-provider-aws to v5.62.0 by
[@&#8203;flostadler](https://togithub.com/flostadler) in
[pulumi/pulumi-aws#4359

**Full Changelog**:
pulumi/pulumi-aws@v6.48.0...v6.49.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.

---

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

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yNS4yIiwidXBkYXRlZEluVmVyIjoiMzguMjUuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsidHlwZS9taW5vciJdfQ==-->

Co-authored-by: lumiere-bot[bot] <98047013+lumiere-bot[bot]@users.noreply.github.com>
lumiere-bot bot added a commit to coolguy1771/home-ops that referenced this pull request Aug 14, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@pulumi/aws](https://pulumi.io)
([source](https://togithub.com/pulumi/pulumi-aws)) | dependencies |
minor | [`6.48.0` ->
`6.49.0`](https://renovatebot.com/diffs/npm/@pulumi%2faws/6.48.0/6.49.0)
|

---

### Release Notes

<details>
<summary>pulumi/pulumi-aws (@&#8203;pulumi/aws)</summary>

###
[`v6.49.0`](https://togithub.com/pulumi/pulumi-aws/releases/tag/v6.49.0)

[Compare
Source](https://togithub.com/pulumi/pulumi-aws/compare/v6.48.0...v6.49.0)

##### Does the PR have any schema changes?

Looking good! No breaking changes found.

##### New resources:

-   `ebs/snapshotBlockPublicAccess.SnapshotBlockPublicAccess`
-   `lambda/callbackFunction.CallbackFunction`
-   `rds/integration.Integration`

##### New functions:

-   `rds/getClusterParameterGroup.getClusterParameterGroup`
-   `secretsmanager/getSecretVersions.getSecretVersions`

##### What's Changed

- Update GitHub Actions workflows. by
[@&#8203;pulumi-bot](https://togithub.com/pulumi-bot) in
[pulumi/pulumi-aws#4353
- Upgrade CallbackFunction default runtime to Node 20.x by
[@&#8203;t0yv0](https://togithub.com/t0yv0) in
[pulumi/pulumi-aws#4348
- Schematize lambda.CallbackFunction overlay and add docs for it by
[@&#8203;flostadler](https://togithub.com/flostadler) in
[pulumi/pulumi-aws#4352
- Upgrade terraform-provider-aws to v5.62.0 by
[@&#8203;flostadler](https://togithub.com/flostadler) in
[pulumi/pulumi-aws#4359

**Full Changelog**:
pulumi/pulumi-aws@v6.48.0...v6.49.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 these
updates again.

---

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

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yNS4yIiwidXBkYXRlZEluVmVyIjoiMzguMjUuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsidHlwZS9taW5vciJdfQ==-->

Co-authored-by: lumiere-bot[bot] <98047013+lumiere-bot[bot]@users.noreply.github.com>
@mjeffryes mjeffryes added this to the 0.108 milestone Aug 16, 2024
@mikhailshilkov
Copy link
Member

This PR has been shipped in release v6.49.0.

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.

Document CallbackFunction resource overlay
4 participants