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
docs: Add example showing how to include sharp in custom lambda #7522
base: main
Are you sure you want to change the base?
Conversation
|
||
> Feel free to adjust the location of the `zip-file` as needed. Also, if using the `AmplifySet` role, you may need to adjust your permissions. | ||
|
||
```sh title="In your terminal" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```sh title="In your terminal" | |
```bash title="Terminal" |
|
||
To get started, ensure you have a Sharp layer deployed to your AWS account. | ||
|
||
## Sharp Layer Deployment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step 1 - Deploy your Lambda layer
|
||
Amplify Functions are powered by [AWS Lambda](https://aws.amazon.com/lambda/), and allow you to perform a wide variety of customization through self-contained _functions_. However, there are times when a feature may not be directly supported through what Amplify exposes. Fortunately, AWS Amplify allows the use of [custom resources](https://docs.amplify.aws/react/build-a-backend/add-aws-services/custom-resources/) to be created. This enables the full flexibility of the [AWS CDK](https://docs.aws.amazon.com/cdk/api/v2/), while still providing a type-safe environment. | ||
|
||
In this section, we'll explore this feature by creating a custom Lambda function that bundles the [Sharp nodejs package](https://www.npmjs.com/package/sharp). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cut from here and put it right below the next heading
|
||
Once deployed, you'll see the ARN of your Lambda layer similar to below: | ||
|
||
```sh title="example lambda layer arn" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```sh title="example lambda layer arn" | |
```console title="Terminal" |
arn:aws:lambda:us-east-1:211125654548:layer:sharp | ||
``` | ||
|
||
It's *very* important to note that we'll needs to specify the version in addition to this ARN. In this example, we'll be adding this layer to a `.env.local` file with the version appended as shown: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's *very* important to note that we'll needs to specify the version in addition to this ARN. In this example, we'll be adding this layer to a `.env.local` file with the version appended as shown: | |
It's **very** important to specify the version in addition to this ARN. In this example, we'll be adding this layer to a `.env.local` file with the version appended as shown: |
SHARP_LAYER_ARN=arn:aws:lambda:us-east-1:211125654548:layer:sharp:1 | ||
``` | ||
|
||
## Creating a custom Lambda Function with a Lambda Layer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Creating a custom Lambda Function with a Lambda Layer | |
## Step 2 - Create a custom Lambda function with a Lambda layer |
) | ||
``` | ||
|
||
Above you can see that we are giving our function a name, where it's handler function is located, the runtime, and that our sharp layer is to be used and considered as externally brought in as a dependency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above you can see that we are giving our function a name, where it's handler function is located, the runtime, and that our sharp layer is to be used and considered as externally brought in as a dependency. | |
Above you can see that we are giving our function a name – where its handler function is located – the runtime, and that our sharp layer is to be used and considered as externally brought in as a dependency. |
|
||
Locally, you will likely want to test out the Sharp library. This can be done by simply installing it as a dev dependency: | ||
|
||
```sh title="installing sharp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```sh title="installing sharp" | |
```sh title="Terminal" |
ope @mtliendo did your page get deleted? |
Description of changes:
This PR creates a new lambda example showing how to use a lambda layer with a custom NodeJsFunction
Related GitHub issue #, if available:
Instructions
If this PR should not be merged upon approval for any reason, please submit as a DRAFT
Which product(s) are affected by this PR (if applicable)?
Which platform(s) are affected by this PR (if applicable)?
Please add the product(s)/platform(s) affected to the PR title
function/examples
Checks
Does this PR conform to the styleguide?
[ x] Does this PR include filetypes other than markdown or images? Please add or update unit tests accordingly.
Are any files being deleted with this PR? If so, have the needed redirects been created?
[ x] Are all links in MDX files using the MDX link syntax rather than HTML link syntax?
ref: MDX:
[link](https://docs.amplify.aws/)
HTML:
<a href="https://docs.amplify.aws/">link</a>
When this PR is ready to merge, please check the box below
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.