Back to Aws Doc Sdk Examples

Deploy a photo asset management application for an AWS SDK with AWS CDK

applications/photo-asset-manager/cdk/README.md

latest3.4 KB
Original Source

Deploy a photo asset management application for an AWS SDK with AWS CDK

The Photo Asset Management (PAM) example app is a React website that supports the upload of photographic images to Amazon S3, automatic categorization of those images using Amazon Rekognition, and retrieval of zipped batches of images matching a provided category.

You will deploy this CDK project using any of the supported language implementations.

PAM CDK Project

This project will create the following in your AWS Cloud environment:

  • AWS Identity and Access Management (IAM) group
  • IAM user (added to the IAM group)
  • Amazon Simple Storage Service (Amazon S3) buckets
  • Amazon DynamoDB tables
  • AWS Lambda function that performs image classification with Amazon Rekognition when new images are uploaded to the S3 bucket
  • Amazon API Gateway routing for Lambda functions
  • Roles and policies allowing appropriate access to these resources

Requirements:


First, you will need to install the dependencies in this project:

npm install

You can check the toolkit version with this command:

$ cdk --version

Export these variables:

NameUsage
PAM_NAMEShort one-word name to identify this stack.
PAM_EMAILEmail address for the pre-verified default user account.
PAM_LANGProgramming language for the Lambdas in this deployment.

Current languages: Java, Python, Dotnet

bash/zsh

export PAM_NAME=
export PAM_EMAIL=
export PAM_LANG=

Windows cmd

set PAM_NAME=
set PAM_EMAIL=
set PAM_LANG=

Windows Powershell

$Env:PAM_NAME =
$Env:PAM_EMAIL =
$Env:PAM_LANG =

There are three stacks that need to be deployed:

  1. PamFrontEndInfraStack ({PAM_NAME}-FE-Infra-PAM) - Amazon Cloudfront distribution and S3 bucket host for static website files.
  2. PamStack ({PAM_NAME}-{PAM_LANG}-PAM) - The backend resources (Amazon Rekognition, Lambda, Amazon S3, Amazon Cognito, API Gateway).
  3. PamFrontEndAssetStack ({PAM_NAME}-FE-Assets-PAM) - The static website assets.

At this point you can now synthesize the AWS CloudFormation template for this code. Run cdk ls to see a list of available stacks to synth/deploy.

cdk synth {PAM_NAME}-FE-Infra-PAM

If everything looks good, go ahead and deploy. This step will make changes to your AWS Cloud environment.

$ cdk bootstrap # Only required once for the lifetime of your account.
$ cdk deploy {STACK_NAME} # Deploy each of the three preceding stacks in order.

Test

After deploying the PamFrontEndInfraStack, your terminal should have a Cloudfront distribution URL. Navigate to that URL to see the deployed app.

Clean up

To clean up, delete the CDK stacks in reverse creation order. Run the following command for each stack:

$ cdk destroy {STACK_NAME}

Useful commands

  • cdk ls List the stacks based on your name and programming language
  • cdk deploy Deploy this stack to your default AWS account/region
  • cdk diff Compare the deployed stack with the current state
  • cdk synth Emits the synthesized CloudFormation template