applications/photo-asset-manager/DEVELOPMENT.md
Photo Asset Management (PAM) is an AWS SDK Code Examples cross-service example. It's one app, with a consistent architecture, implemented in several programming languages supported by AWS SDKs. This folder has the AWS Cloud Development Kit (CDK) resources to deploy the entire app, including AWS resources, the React front end, and the per-language AWS Lambda implementations.
To add a new supported implementation language:
./lib/backend/strategies.ts and add a new PamLambdaStrategy for the language.
(Copy or refer to an existing instance.)
STRATEGIES constant.PamLambdaStrategyThe PamLambdaStrategy interface describes how the AWS CDK will deploy the Lambdas for a language.
runtime uses a constant from the published Lambda Runtime.
If a static entry is available, use it. Otherwise, create a new Runtime as appropriate.
timeout and memorySize specify the limits the Lambda will impose.
The defaults might be fine, but expect to need to tune these.
export interface PamLambdasStrategy {
runtime: Runtime;
timeout: Duration; // Default is 15 minutes.
memorySize: number; // In megabytes.
codeAsset: () => Code; // See Bundle code, following.
handlers: PamLambdasStrategyHandlers; // See Handlers, following
}
The strategy codeAsset property is a function that returns an AWS CDK Code reference.
This is the code that Lambda executes directly.
Code.fromAsset using the NodeJS resolve path utility can load any code from the aws-doc-sdk-examples repository. It is specified relative to resources/cdk/photo_asset_manager.
For interpreted languages, this might be all that's necessary for the code.
For compiled languages, Lambda requires the compiled assets.
The AWS CDK can compile resources during the deployment using docker.
To configure this, use the bundling option of Code.fromAsset.
Languages with a well-known Runtime usually have a Runtime.image property that has an appropriate docker base image.
Otherwise, any public docker image is suitable.
Docker will execute the command for the bundling step.
The assets, specified as the first argument to Code.fromAsset, are mounted in the container at /asset-input/ (which is also the working directory).
The command should perform any compilation steps necessary, and move any necessary artifacts to /asset-output/.
The contents of /asset-output/ are archived in the Lambda's Amazon Simple Storage Service (Amazon S3) bucket. These contents are the executable that the Runtime uses.
In this setup, the output bundle has code for all the Lambdas. To specify which handler gets executed, specify the handler for each. The exact format of the handler string is language dependent, and will require research for each. For instance, the Java handler specifies the classpath to load. The Python handler specifies the entire module and function to execute.
When implementing Lambda functions, application AWS resources are available in the following environment variables.
| Variable | Usage |
|---|---|
LABELS_TABLE_NAME | Name for the Labels Table |
STORAGE_BUCKET_NAME | Name for the Storage Bucket |
WORKING_BUCKET_NAME | Name for the Working Bucket |
NOTIFICATION_TOPIC | Amazon Resource Name (ARN) of the Amazon Simple Notification Service (Amazon SNS) topic to send download ready notifications to. |
file_name field from the body (which needs to be parsed as JSON).url response body (which will need to be encoded as JSON).detectLabels.count, with the integer count column.body field. There is no response.body as JSON and get the labels column, an array of strings.PAM_NAME, PAM_EMAIl, and PAM_LANG (using your new language).cdk deploy ${PAM_NAME}-FE-Infra-PAMcdk deploy ${PAM_NAME}-${PAM_LANG}-PAMcdk deploy ${PAM_NAME}-FE-Assets-PAMcdk deploy ${PAM_NAME}-${PAM_LANG}-PAM.