Skip to content

Commit

Permalink
Implement file set (video) download route
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Oct 13, 2023
1 parent e3fd2aa commit 310fb2a
Show file tree
Hide file tree
Showing 24 changed files with 14,841 additions and 2,308 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
nodejs 16.14.0
java corretto-19.0.1.10.1
aws-sam-cli 1.97.0
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,34 @@ npm run dev

Access the app in a browser at: https://USER_PREFIX.dev.rdc.library.northwestern.edu:3003/

## Running the API locally with state machine + lambdas (needed for AV download route)

```shell
# From the repo root
cd dc-api-v2

# Make sure you've done an `npm install` recently to update any packages in the `lambdas` directory
npm install

# Start the proxy (if needed)
https-proxy start 3002 3000

# Open port 3005 (if needed)
sg open all 3005

# Login as the staging-admin user
export AWS_PROFILE=staging-admin
aws sso login

# Start the API + step function and associated lambdas
bin/start-with-step

# Open a second terminal and create the state machine
aws stepfunctions create-state-machine --endpoint http://localhost:8083 --definition file://state_machines/av_download.json --name "hlsStitcherStepFunction" --role-arn arn:aws:iam::012345678901:role/DummyRole
```



## Deploying the API manually

- Symlink the `*.parameters` file you need from `tfvars/dc-api/` to the application root
Expand Down
6 changes: 6 additions & 0 deletions bin/start-with-step
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

sam local start-lambda --host 0.0.0.0 --port 3005 --env-vars env.json --log-file lambda.log & lambda_pid=$!
sam local start-api --host 0.0.0.0 --log-file dc-api.log & api_pid=$!
docker run --rm -p 8083:8083 -e LAMBDA_ENDPOINT=http://172.17.0.1:3005/ amazon/aws-stepfunctions-local
kill $api_pid $lambda_pid
25 changes: 25 additions & 0 deletions docs/docs/spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ paths:
description: "The resource is authorized"
403:
description: "The resource is not authorized"
/file-sets/{id}/download:
get:
operationId: getFileSetDownload
tags:
- FileSet
parameters:
- name: id
description: Id of the file set
in: path
required: true
schema:
type: string
- name: email
description: Email to send the download link to
in: query
required: true
schema:
type: string
responses:
200:
description: "The download is being created"
400:
description: "Bad Request"
405:
description: "Method Not allowed for work type, file set role combo"
/works/{id}:
get:
operationId: getWorkById
Expand Down
27 changes: 27 additions & 0 deletions lambdas/get-download-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* istanbul ignore file */
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");

module.exports.handler = async (event) => {

console.log("PRESIGNED URL LAMBDA")
console.log(event)

const clientParams = {}

const getObjectParams = {
"Bucket": event.bucket,
"Key": event.key
}

const client = new S3Client(clientParams);
const command = new GetObjectCommand(getObjectParams);
const url = await getSignedUrl(client, command, { expiresIn: 3600 });

console.log("url", url)

return {downloadLink: url}

};


Loading

0 comments on commit 310fb2a

Please sign in to comment.