Post-processing

Post-processing

The last lambda function in the image processing is fired when the final image is rendered and saved to the S3 image processor. It will save the image object information to the DynamoDB table and send a notification to the IoT topic for the front-end application to be notified.

Create Lambda function

  1. Access to Lambda
  2. Select Create function

VS Code

  1. In the Create function interface

    • Select Author from catch
    • For Basic information, enter theme-park-photos-postprocess
    • For Runtime, select Node.js 14.x
    • For Architecture, choose x86_64
    • Choose to expand Change default execution role

VS Code

  1. In the Change default execution role interface

    • Select Use an existing role
    • Select theme-park-backend-ThemeParkLambdaRole
    • Select Create function

VS Code

  1. Finish creating Lambda function

    • Select + Add trigger

VS Code

  1. In the Trigger configuration page

    • Select S3
    • Bucket, select theme-park-backend-finalbucket
    • For Event Type, select All object create events
    • Select Recursive invocation acknowledgment
    • Select Add

VS Code

  1. Complete Add trigger S3

    • Select Code tab.

VS Code

  1. Return to VS Code interface

    • Select 3-postprocess/app.js
    • Copy the code of app.js

VS Code

  1. Paste the code of app.js into index.js

    • Save
    • Select Deploy

VS Code

Add environment variables.

This function uses two environment variables:

  • IOT_DATA_ENDPOINT: IoT endpoint hostname.
  • DDB_TABLE_NAME: DynamoDB table name used by the application.
  1. Return to your browser tab while VS Code is running
  2. In the terminal, enter the following command to retrieve the value for IOT_DATA_ENDPOINT:
aws iot describe-endpoint --endpoint-type iot:Data-ATS
  1. Next, enter the following command to retrieve the value for DDB_TABLE_NAME:
aws dynamodb list-tables | grep backend

VS Code

  1. Go back to theme-park-photos-postprocess Lambda function.
  • Select Configuration tab
  • Select Environment variables
  • Select Edit

VS Code

  1. Enter the two environment variable names along with the values ​​you retrieved in VS Code (without the quotes):
  • Select Save

VS Code

  1. Finish adding environment variables.

VS Code

Front-end update

  1. Return to your browser tab while VS Code is running
  2. In the terminal , run this command to expose the upload API since the backend is implemented in module 1:
aws cloudformation describe-stacks --stack-name theme-park-backend --query "Stacks[0].Outputs[?OutputKey=='UploadApi'].OutputValue" --output text

VS Code

  1. Copy the output URL to the clipboard:

VS Code

  1. In Terminal VS Code, in the left directory panel, navigate to theme-park-frontend/src

  2. Find config.js and double click to open it in the editor. This file contains the JSON configuration for the front-end.

  3. In the MODULE 3 section, between the quotes ‘’, update photoUploadURL with API Endpoint URL in the clipboard.

  4. Then save the file.

VS Code

Push CodeCommit and Deploy via Amplify

  1. In Terminal VS Code, change to the front-end directory with the following command:
cd ~/sampleapp/theme-park-frontend/
  1. Commit CodeCommit by executing the following commands:
git commit -am "Module 3 - Photo compositing"
git push

VS Code

  1. After the commit is complete, go to Amplify Console

VS Code

  1. On All apps page
  • Select theme-park-frontend
  1. You should see a new build automatically started as a result of the new commit in the underlying code repo. This build will take a few minutes until the Verification phase is complete

VS Code

  1. Open the published application URL in the browser.

VS Code

  1. Click one of the trip profiles to open the trip description page. You can see a new button has appeared - “Add ride photo”.

VS Code