Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit 7b19c40

Browse files
committed
chore: add an example s3 backed ipfs setup
License: MIT Signed-off-by: Jacob Heun <[email protected]>
1 parent 104d6e9 commit 7b19c40

File tree

4 files changed

+108
-4
lines changed

4 files changed

+108
-4
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ A bucket must be created prior to using datastore-s3. Please see the AWS docs fo
3030

3131
```js
3232
const S3 = require('aws-sdk').S3
33-
const s3Instance = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
33+
const s3Instance = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
3434
const S3Store = require('datastore-s3')
35-
const store = new S3Store('.ipfs/datastore', {
36-
s3: s3Instance
37-
})
35+
const store = new S3Store('.ipfs/datastore', {
36+
s3: s3Instance
37+
})
3838
```
3939

40+
### Examples
41+
You can see examples of S3 backed ipfs in the [examples folder](examples/)
42+
4043
## Contribute
4144

4245
PRs accepted.

examples/full-s3-repo/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Full S3 Repo
2+
======
3+
4+
This example leverages the code from https://github.com/ipfs/js-ipfs/tree/master/examples/ipfs-101,
5+
but uses an instantiated S3 instance to serve as the entire backend for ipfs.
6+
7+
## Running
8+
The S3 parameters must be updated with an existing Bucket and credentials with access to it:
9+
```js
10+
const s3 = new S3({
11+
params: {
12+
Bucket: 'my-bucket'
13+
},
14+
accessKeyId: 'myaccesskey',
15+
secretAccessKey: 'mysecretkey'
16+
})
17+
```
18+
19+
Once the S3 instance has its needed data, you can run the example:
20+
```
21+
npm install
22+
node index.js
23+
```

examples/full-s3-repo/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict'
2+
3+
const series = require('async/series')
4+
const IPFS = require('ipfs')
5+
const Repo = require('ipfs-repo')
6+
const S3 = require('aws-sdk').S3
7+
const S3Store = require('../../src')
8+
9+
let fileMultihash
10+
const s3 = new S3({
11+
params: {
12+
Bucket: 'my-bucket'
13+
},
14+
accessKeyId: 'myaccesskey',
15+
secretAccessKey: 'mysecretkey'
16+
})
17+
18+
const repo = new Repo('/tmp/test/.ipfs', {
19+
storageBackends: {
20+
root: S3Store,
21+
blocks: S3Store,
22+
keys: S3Store,
23+
datastore: S3Store
24+
},
25+
storageBackendOptions: {
26+
root: { s3 },
27+
blocks: { s3 },
28+
keys: { s3 },
29+
datastore: { s3 }
30+
}
31+
})
32+
33+
let node = new IPFS({
34+
repo: repo
35+
})
36+
37+
series([
38+
(cb) => node.on('ready', cb),
39+
(cb) => node.version((err, version) => {
40+
if (err) { return cb(err) }
41+
console.log('Version:', version.version)
42+
cb()
43+
}),
44+
(cb) => node.files.add({
45+
path: 'hello.txt',
46+
content: Buffer.from('Hello World 101')
47+
}, (err, filesAdded) => {
48+
if (err) { return cb(err) }
49+
50+
console.log('\nAdded file:', filesAdded[0].path, filesAdded[0].hash)
51+
fileMultihash = filesAdded[0].hash
52+
cb()
53+
}),
54+
(cb) => node.files.cat(fileMultihash, (err, data) => {
55+
if (err) { return cb(err) }
56+
57+
console.log('\nFile content:')
58+
process.stdout.write(data)
59+
})
60+
])

examples/full-s3-repo/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "full-s3-repo",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"async": "^2.6.0",
14+
"aws-sdk": "^2.220.1",
15+
"ipfs": "^0.28.2",
16+
"ipfs-repo": "^0.18.7"
17+
}
18+
}

0 commit comments

Comments
 (0)