Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial implementation #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Deploy
on: [workflow_dispatch]
env:
AWS_REGION: us-east-2
LAMBDA: assemble-cars
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js Current
uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Restore cached dependencies
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package.json') }}
- name: Install dependencies
run: npm install
vasco-santos marked this conversation as resolved.
Show resolved Hide resolved
- name: Lint code
run: npm run lint
- name: Build
run: npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Deploy
run: npm run deploy
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- '**'

jobs:
test:
runs-on: ubuntu-latest
name: Test
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
Copy link

@olizilla olizilla Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why test on node 14 when the deploy script uses 16?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWS does not support node16 https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

Deploy script is irrelevant, but I think we can change to 14

- uses: bahmutov/npm-install@v1
- run: npm run test
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# assemble-cars-lambda

The `assemble-cars-lambda` will trigger on writes to a given S3 bucket and assemble partial raw CAR files into complete CAR files.

Once a CAR is written, the lambda function will inspect its completeness, as well as if its wrapping directory as all the CARs of the DAG. If we can traverse all the DAG, the partial CARs will be joined and stored on a `/complete` namespace.

## Assumptions

There are a few assumptions in place and this lambda function will assemble CARs if:
- S3 Object Metadata has a "Complete" structure
- S3 Object has a DagPB encoded root with a known size __acceptable__ (100MB) and the S3 directory for that root CID already has all the DAG chunks
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: Need to tweak size yet


## AWS Setup

This project already comes with a script for build and deploy (which is also integrated with Github Actions). However it needs:
- Project creation in AWS
- It needs a role policy with S3 `s3:GetObject`, `s3:PutObject` and `s3:ListBucket` privileges
- Secrets setup in Repo secrets for automatic deploy
- Environment variables setup

## Development and AWS bootstrap

Set environment variables in a `.env.local` file in the root directory of this project:

```env
AWS_ACCESS_KEY_ID=""
AWS_SECRET_ACCESS_KEY=""
AWS_REGION=""
AWS_BUCKET=""
NAME="dotstorage-assemble-cars"
```

```sh
npm run init
```

## What's next?

- CBOR
- What to do with really large CAR files ?
29 changes: 29 additions & 0 deletions aws/lambda-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "arn:aws:logs:::*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:::::*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::*"
}
]
}
12 changes: 12 additions & 0 deletions aws/role-trust-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
21 changes: 21 additions & 0 deletions aws/s3-trigger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"LambdaFunctionConfigurations": [
{
"Id": "assemble-cars-notification",
"LambdaFunctionArn": "TODO",
"Events": [
"s3:ObjectCreated:*"
],
"Filter": {
"Key": {
"FilterRules": [
{
"Name": "prefix",
"Value": "raw"
}
]
}
}
}
]
}
Loading