parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

S3Adaptor not writing to S3

Open Abderezai opened this issue 10 years ago • 25 comments

I instantiated the S3 adaptor in the parse server init, but the files I upload are still going to the GridFile (MongoDB). I'm not getting any warning as to why the S3 is failing (or if it even is). The instructions posted on the wiki seem to be missing something in regards to the Policy. Do we need an Sid? Principle?

filesAdapter: new S3Adapter( "Key_ID", "Acess_KEY", "BUCKET_NAME", { directAccess: true })

I know this is not detailed. But I followed the instructions to the T, and looked on stack overflow and found same issue with no response. http://stackoverflow.com/questions/36536615/parse-s3fileadapter

Any help would be greatly appreciated. Maybe also add a feature where if the S3 setup is not working then generate a warning.

Abderezai avatar Jul 13 '16 01:07 Abderezai

also related to #7 ?

Abderezai avatar Jul 13 '16 06:07 Abderezai

Are you using "US Standard" location for your S3 cloud?

ValeryVa avatar Jul 13 '16 07:07 ValeryVa

@Abderezai

I'm using this script and it's work fine

filesAdapter: new S3Adapter(
      "ACCESS_KEY",
      "SECRET_KEY",
      "BUCKET_NAME",
      "REGION"
)

si294r avatar Jul 13 '16 13:07 si294r

I even tried : filesAdapter: new S3Adapter( "ACCESS_KEY", "SECRET_KEY", "BUCKET_NAME" )

what version of fileadaptor are you using?

Abderezai avatar Jul 13 '16 19:07 Abderezai

i think i'm using version 1.0.2

root@api:/usr/lib/node_modules/parse-server-s3-adapter# ls -la
total 40
drwxr-xr-x 4 nobody root 4096 Apr 27 06:05 .
drwxr-xr-x 7 root   root 4096 May 13 04:05 ..
-rw-r--r-- 1 nobody root 4915 Apr 25 17:16 index.js
drwxr-xr-x 8 root   root 4096 Apr 27 06:05 node_modules
-rw-r--r-- 1 nobody root  529 Apr 25 17:16 .npmignore
-rw-r--r-- 1 root   root 2478 Apr 27 06:05 package.json
-rw-r--r-- 1 nobody root 2321 Apr 25 17:16 README.md
drwxr-xr-x 3 nobody root 4096 Apr 27 06:05 spec
-rw-r--r-- 1 nobody root 3700 Apr 25 17:16 .travis.yml
root@api:/usr/lib/node_modules/parse-server-s3-adapter# cat package.json 
{
  "_args": [
    [
      "parse-server-s3-adapter",
      ""
    ]
  ],
  "_from": "parse-server-s3-adapter@latest",
  "_id": "[email protected]",
  "_inCache": true,
  "_installable": true,
  "_location": "/parse-server-s3-adapter",
  "_nodeVersion": "4.3.2",
  "_npmOperationalInternal": {
    "host": "packages-12-west.internal.npmjs.com",
    "tmp": "tmp/parse-server-s3-adapter-1.0.2.tgz_1461604588508_0.7557203851174563"
  },
  "_npmUser": {
    "email": "[email protected]",
    "name": "flovilmart"
  },
.....

si294r avatar Jul 15 '16 04:07 si294r

just updated to version 1.0.3

 root@api:~# npm update -g parse-server-s3-adapter
 /usr/lib
 └── [email protected] 

si294r avatar Jul 15 '16 07:07 si294r

I've just submit a PR 2288 I hope these PR will help others that need S3Adapter.

si294r avatar Jul 15 '16 09:07 si294r

@si294r I saw your PR, I'll have a look at the loader that we have for all adapters and update the documentation accordingly, as well as probably adding more verbose logs to help you debug your configuraiin

flovilmart avatar Jul 15 '16 13:07 flovilmart

@si294r I just tried without your PR and the S3 adapter is properly loaded from the environment:

PARSE_SERVER_FILES_ADAPTER=parse-server-s3-adapter S3_ACCESS_KEY=hello S3_SECRET_KEY=world S3_BUCKET=boom ./bin/parse-server --appId hello --masterKey world
appId: hello
masterKey: ***REDACTED***
port: 1337
mountPath: /parse
filesAdapter: parse-server-s3-adapter
maxUploadSize: 20mb
serverURL: http://localhost:1337/parse
// in loadAdapter function: 
Trying parse-server-s3-adapter
// in loadAdapter function: 
Trying function S3Adapter() {
  var options = optionsFromArguments(arguments);
  this._region = options.region;
  this._bucket = options.bucket;
  this._bucketPrefix = options.bucketPrefix;
  this._directAccess = options.directAccess;
  this._baseUrl = options.baseUrl;
  this._baseUrlDirect = options.baseUrlDirect;

  let s3Options = {
    accessKeyId: options.accessKey,
    secretAccessKey: options.secretKey,
    params: { Bucket: this._bucket },
    region: this._region
  };
  this._s3Client = new AWS.S3(s3Options);
  this._hasBucket = false;
}
// console.log(filesControllerAdapter);
S3Adapter {
  _region: 'us-east-1',
  _bucket: 'boom',
  _bucketPrefix: '',
  _directAccess: false,
  _baseUrl: null,
  _baseUrlDirect: false,
  _s3Client: 
   Service {
     config: 
      Config {
        credentials: [Object],
        credentialProvider: [Object],
        region: 'us-east-1',
        logger: null,
        apiVersions: {},
        apiVersion: null,
        endpoint: 's3.amazonaws.com',
        httpOptions: [Object],
        maxRetries: undefined,
        maxRedirects: 10,
        paramValidation: true,
        sslEnabled: true,
        s3ForcePathStyle: false,
        s3BucketEndpoint: false,
        s3DisableBodySigning: true,
        computeChecksums: true,
        convertResponseTypes: true,
        correctClockSkew: false,
        customUserAgent: null,
        dynamoDbCrc32: true,
        systemClockOffset: 0,
        signatureVersion: 's3',
        signatureCache: true,
        retryDelayOptions: [Object],
        useAccelerateEndpoint: false,
        accessKeyId: 'hello',
        secretAccessKey: 'world',
        params: [Object] },
     isGlobalEndpoint: false,
     endpoint: 
      Endpoint {
        protocol: 'https:',
        host: 's3.amazonaws.com',
        port: 443,
        hostname: 's3.amazonaws.com',
        pathname: '/',
        path: '/',
        href: 'https://s3.amazonaws.com/' } },
  _hasBucket: false }

flovilmart avatar Jul 15 '16 16:07 flovilmart

I used signatureVersion version 4 I added the this signatureVersion: 'v4' to s3 adapter index.js s3options functions and thats solved my problem

mkaya93 avatar Jul 18 '16 16:07 mkaya93

We may wanna upgrade to v4 by default...

flovilmart avatar Jul 18 '16 16:07 flovilmart

The latest version of parse-server-s3-adapter has v4 signature by default and it's gonna be part of the next release

flovilmart avatar Jul 19 '16 01:07 flovilmart

This is still not working for me. I followed the instructions for setting up my S3 bucket. As for the configuration I figured the documentation must be outdated. So, I ended up with these env variables in my ecosystem.json:

"PARSE_SERVER_FILES_ADAPTER": "parse-server-s3-adapter",
"S3_ACCESS_KEY": "accesskeyid",
"S3_SECRET_KEY": "secretaccesskey",
"S3_BUCKET": "bucketname",
"S3_REGION": "eu-central-1"

I can see from the pm2 logs, that the server is properly started with S3:

publicServerURL: <my public server url>
cloud: /home/parse/cloud/main.js
mountPath: /parse
filesAdapter: parse-server-s3-adapter
emailAdapter: [object Object]
verifyUserEmails: false
preventLoginWithUnverifiedEmail: false
appName: <myappname>
maxUploadSize: 20mb
verbose: 1
serverURL: http://localhost:1337/parse
parse-server running on http://localhost:1337/parse

But whenever I attempt to upload a file from my clients or through the dashboard it fails on {"message":"Could not store file.","code":130}.

Access files through the dashboard now also always results in a File not found.

My environment: Parse-Server: 2.2.17 on DigitalOcean (FRA1) Parse-Dashboard: 1.0.15 Database: mLab parse-server-s3-adapter: 1.0.4

majidhassan avatar Jul 27 '16 11:07 majidhassan

update your parse server or

in parse-server-s3-adapter/index.js change s3Options to this


 let s3Options = {
    accessKeyId: options.accessKey,
    secretAccessKey: options.secretKey,
    params: { Bucket: this._bucket },
    region: this._region,
    signatureVersion: 'v4'
  };
  this._s3Client = new AWS.S3(s3Options);
  this._hasBucket = false;
}

mkaya93 avatar Jul 27 '16 14:07 mkaya93

Hey @mkaya93, I'm using pm2 to run parse-server. So, I'm setting all up using environment variables. Besides the code posted above, I also tried this in my ecosystem.json:

"PARSE_SERVER_FILES_ADAPTER" : {
    "module": "parse-server-s3-adapter",
    "options": {
        "accessKey": "accesskeyid",
        "secretKey": "secretaccesskey",
        "bucket": "bucketname",
        "region": "eu-central-1"
    }
}

Which results in the same { code: 130, message: 'Could not store file.' } error.

I also tried replacing accessKey with your proposed accessKeyId which resulted in the error: S3Adapter requires option 'accessKey' or env. variable S3_ACCESS_KEY.

majidhassan avatar Jul 27 '16 19:07 majidhassan

@majidhassan I'm using pm2 for run my application. Change the this._signatureVersion to 'v4' and try it again my applciation is working perfect with this configuration

mkaya93 avatar Jul 28 '16 11:07 mkaya93

Are you using an index.js with pm2? I'm running it directly with the parse-server command and env variables.

If so, could you please send me your index.js and ecosystem.json files?

majidhassan avatar Jul 28 '16 11:07 majidhassan

My bad, it worked. I had a problem with my policy.

majidhassan avatar Jul 28 '16 12:07 majidhassan

What was the problem with the policy? I'm also having issues - followed the wiki example.

my index.js is as follows:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var S3Adapter = require('parse-server-s3-adapter');

// some db stuff


var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '', 
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', 
  liveQuery: {
    classNames: ["Posts", "Comments"]
  },
  filesAdapter: new S3Adapter(
    process.env.S3_ACCESS_KEY, // 'my key'
    process.env.S3_SECRET_KEY, // 'my secret'
    process.env.S3_BUCKET, // 'my bucket'
    {
      directAccess: process.env.S3_DIRECT_ACCESS, //'true'
      region: process.env.S3_REGION, // 'eu-west-1'
      bucketPrefix: process.env.S3_BUCKET_PREFIX, // 'coolprefix'
      signatureVersion: 'v4'
    }
  ),
});

raubas avatar Jul 31 '16 21:07 raubas

@majidhassan I'm not getting error from parse and s3 adapter.I just tried to help you for solve your problem.

mkaya93 avatar Jul 31 '16 22:07 mkaya93