Complete Example (click to hide)
0) Review the quick start for JavaScript on AWS
1) Create a new folder and download [`index.js`](pathname:///aws/index.js):
```bash
mkdir -p SheetJSLambda
cd SheetJSLambda
curl -LO https://docs.sheetjs.com/aws/index.js
```
2) Install dependencies in the project directory;
{`\
mkdir -p node_modules
npm install https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz busboy`}
3) Create a .zip package of the contents of the folder:
```bash
yes | zip -c ../SheetJSLambda.zip -r .
```
4) In the web interface for AWS Lambda, create a new Function with the options:
- Select "Author from scratch" (default choice when last verified)
- "Function Name": SheetJSLambda
- "Runtime": "Node.js" (select the version in the "Latest supported" block)
- Advanced Settings:
+ check "Enable function URL"
+ Auth type: NONE
+ Check "Configure cross-origin resource sharing (CORS)"
5) In the Interface, click "Upload from" and select ".zip file". Click the
"Upload" button in the modal, select SheetJSLambda.zip, and click "Save".
When the demo was last tested, the ZIP was small enough that the Lambda code
editor will load the package.
6) Enable external access to the function.
Under Configuration > Function URL, click "Edit" and ensure that Auth type is
set to NONE. If it is not, select NONE and click Save.
Under Configuration > Permissions, scroll down to "Resource-based policy".
If no policy statements are defined, select "Add Permission" with the options:
- Select "Function URL" at the top
- Auth type: NONE
- Ensure that Statement ID is set to `FunctionURLAllowPublicAccess`
- Ensure that Principal is set to `*`
- Ensure that Action is set to `lambda:InvokeFunctionUrl`
Click "Save" and a new Policy statement should be created.
7) Find the Function URL (It is in the "Function Overview" section).
Try to access that URL in a web browser and the site will try to download
`SheetJSLambda.xlsx`. Save and open the file to confirm it is valid.
To test parsing, download and make a POST
request to the public function URL (change `FUNCTION_URL` in the command):
```bash
curl -X POST -F "upload=@pres.numbers" FUNCTION_URL
```
The result should be a CSV output of the first sheet.
## S3 Storage
The main module for S3 and all AWS services is `aws-sdk`.
### Reading Data
The `s3#getObject` method returns an object with a `createReadStream` method.
Buffers can be concatenated and passed to `XLSX.read`.