An AWS lambda function to upload an OBJ file to Autodesk Cloud and translate it to SVF format.
This server app uses the Forge Data Management and Model Derivatives APIs to upload an OBJ file to a OSS bucket and then translate the OBJ file to a viewable format (SVF) that the Forge Viewer can open.
The flow is simple:
After the photoscene has been successfully processed, the mobile app has access to a photoscenelink URL that can be used to download the resulting OBJ file.
- The server app logs into Forge using 2-legged oAuth flow
- The server app uploads the OBJ file to an OSS bucket
- The server app translates the OBJ file to SVF format
- The resulting viewable files are then uploaded to S3 bucket
- The mobile app can now view the 3D model
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
- 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
- Edit the file
config.js
to change the bucket name underBUCKET_KEY
. Pick a name that is unique to you. - Save the changes
- Run
npm run create
to send everything up to AWS Lambda. It will return a 'new URL'. - Run
npm run setvars
to push the environment variables to Lambda.
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_S3_BUCKET 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_UPLOAD_TRANSLATE_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. Wait for the OBJ file to be translated. When ready, the View File button will become available, click on it to launch the Forge Viewer and open the viewables.
- 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.