Back to Aws Doc Sdk Examples

Create a photo asset management application with the SDK for JavaScript

javascriptv3/example_code/cross-services/photo-asset-manager/README.md

latest4.9 KB
Original Source

Create a photo asset management application with the SDK for JavaScript

Overview

This example shows you how to use the AWS SDK for JavaScript (v3) to create a photo asset management application using AWS services and a serverless architecture.

The Photo Asset Management (PAM) example app uses Amazon Rekognition to categorize images, which are stored with Amazon Simple Storage Service (Amazon S3) Intelligent-Tiering for cost savings. Users can upload new images. Those images are analyzed with label detection and the labels are stored in an Amazon DynamoDB table. Users can later request a bundle of images matching those labels. When images are requested, they are retrieved from Amazon S3, zipped, and the user is sent a link to the zip.

⚠️ Important

  • Running this code might result in charges to your AWS account.
  • Running the tests might result in charges to your AWS account.
  • We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
  • This code is not tested in every AWS Region. For more information, see AWS Regional Services.

Prerequisites

  • An AWS account.
  • NodeJS 18+.
  • Docker Desktop.

Structure

The PAM example has both shared resources and language-specific AWS Lambda functions. The CDK files let you deploy the shared resources and choose which set of functions to deploy to Lambda. This README is for the JavaScript Lambda functions.

Create the resources

Follow the instructions in the README for the Photo Asset Manager application to use the AWS Cloud Development Kit (AWS CDK) or AWS Command Line Interface (AWS CLI) to create and manage the resources used in this example. You must be running Docker in order to complete the steps for this CDK.

Build the code

The Lambda handlers are written in ESM and deployed as ESM with the added step of being bundled into one file.

This bundling happens automatically when you deploy the <PAM_NAME>-<PAM_LANG>-PAM stack. The CDK bundling step will run npm run build and then deploy the output to Lambda. The CDK step is declared here.

Usage

Follow the steps in the README for the Photo Asset Manager front-end.

Delete the resources

To avoid charges, delete all the resources that you created for this tutorial. Follow the steps in README for the Photo Asset Manager CDK to clean up the resources for the CDK stacks.

Next steps

Congratulations! You have created and deployed a photo asset management application.

Additional resources

Questions

Why Vitest?

  • Supports ESM without any additional configuration.
  • Uses Vite to transform files during testing. This allows named imports from all CJS modules and other features.
  • Uses the popular Chai assertion library.

Why Rollup and not Vite?

Vitest is being used as the test runner, but Vite is made for browser development. It uses Rollup under the hood for bundling libraries, but configuration is simpler when Rollup is used independently.

When bundling with Vite, it bundles for the browser, so any NodeJS natives without polyfills will cause an error to be thrown. Turning on Vite's server-side rendering feature gets around this, but it makes it less clear what we're trying to do. The configuration got to a point where it seemed more opaque than helpful. Falling back to pure Rollup clarified things.


Have more questions? Create an issue.