AWS lambda backend app for the Autodesk Forge Reality Capture mobile app.
This server app calls the Forge Reality Capture API to process images found on your smartphone and generate an OBJ file. An OBJ file is an open geometry definition file format that represents 3D geometry alone.
The flow is simple:
The mobile app lets users select image files from the camera roll and upload them to a S3 bucket.
- The server app logs into Forge using 2-legged oAuth flow
- The server app creates a new photoscene. The API documentation is found here
- The images are added to the photoscene using the images' S3 URLs. The API documentation can be accessed here
- The photoscene is sent for processing. Refer to API documentation here
- When the processing is complete, the callback URL is hit and a photoscene link is returned
Before you start, make sure you read Serverless Code with Amazons AWS and Claudia to learn more about the setup.
- Create a new repository directory
- Download this repository and extract to the new directory
- Install Node.js and npm
- Run
npm install npm@latest -g
Redis Cloud is used here to store session data. AWS Lambda functions are stateless, hence the need to store session information and persist it elsewhere. Redis database will be used to persist the photoscenelink URL, photoscene ID and other parameters.
- Sign-up for a free Redis Cloud account here
- Setup a new subscription, database and connect by following the quick setup guide
- Browse to the repository directory
- Run
npm install
- Edit the file
package.json
to change the app name on line 2. Pick a name that is unique to you. - Continue editing the same file
package.json
to update the Forge App ID and secret, Amazon S3 bucket and Redis password on the setvars script line--set-env FORGE_APP_ID=xxx,FORGE_APP_SECRET=yyy,S3_BUCKET=reality-capture-images,REDIS_PASSWORD=zzz
- Save the changes
- Run
npm run create
to send everything up to AWS Lambda. It will return a 'new URL', make a note of its value as you will need to input the URL in the config.js file under the AWS_LAMBDA_BASE_ENDPOINT variable.
- Run
npm run setvars
to push the environment variables to Lambda. - Open the 'new URL' in a browser
Example: https://adc6qwtnce.execute-api.us-east-1.amazonaws.com/demo/
Remember to add a '/' or a '/index.html' to the URL.
Below I demonstrate 'Claudia.js' 'update' command to re-deploy a small code change. Claudia handles the task of zipping, uploading and re-wiring node.js endpoints to 'AWS-Lambda & API-Gateway' automatically.
- Using your favorite text editor, open the config.js file from the root directory
- Input the correct values in REDIS_ENDPOINT and AWS_LAMBDA_BASE_ENDPOINT variables, save the changes
- Run
npm run update
...
Anytime you need to make code changes, you should use the 'update' command to push your changes to the AWS lambda function.
- Login to your AWS console
- Navigate to Lambda Functions
- Open your new Lambda function
- Change the Node.js version to 8.10
- Increase memory to 512 Mb and timeout value to 30 seconds
- Connect the demo alias to $LATEST version
- Save the changes
Go back to your mobile app to edit the ./constants/Config.js
file to have the correct AWS lambda endpoint in the variable named AWS_RECAP_LAMBDA_BASE_ENDPOINT. Save the change and submit 3 or more images for processing by pressing the button called "Process Photoscene".
This should generate a new OBJ file. You can validate the photoscenelink has the right data by browsing to the AWS lambda function endpoint /demo/redis/photoscenelink and use that URL to download the OBJ file locally.
- Amazon Lambda - Run code without thinking about servers.
- Amazon API Gateway - Fully managed service to create, publish, maintain, monitor, and secure APIs.
- Amazon S3 - Amazon Simple Storage Service.
- Claudia JS - JavaScript cloud micro-services the easy way.
- NodeJS - JavaScript runtime.
- Express - Fast, unopiniated, minimalist web framework for Node.js.
- AWS SDK - AWS SDK for JavaScript in the browser and Node.js.
- AWS Serverless Express - AWS Serverless JavaScript framework.
Bastien Mazeran @BastienMazeran, Autodesk Inc.
This project is licensed under the MIT License - see the LICENSE file for details.
This code came from GITHUB-Express-Lambda
More information on Express/Serverless can be found here: Running Express Apps in AWS Lambda
The package.json was modified from here: Package.json
Inspired by this blog post, by Philippe Leefsma.