When I try a simple spaces upload using the aws -sdk I keep getting the error: ‘InvalidAccessKeyId: null’,
here is the code with my secret key redacted:
const AWS = require(‘aws-sdk’); const fs = require(‘fs’);
const publicKey = ‘AKIAIEPGV5ULZ34YOZPA’; const secretKey = ‘redacted’;
AWS.config.update({region: ‘nyc3’, accessKeyId: publicKey, secretAccessKey: secretKey});
let spacesEndpoint = new AWS.Endpoint(‘nyc3.digitaloceanspaces.com’); let s3 = new AWS.S3({ endpoint: spacesEndpoint, region: ‘nyc3’, params: { Bucket: ‘packix’, ContentType: ‘application/x-debian-package’, ACL: ‘private’ } });
let testParams = { Key: ‘packix_test_deb’ };
let debStream = fs.createReadStream(‘test.deb’); testParams[‘Body’] = debStream;
s3.upload(testParams) .on(‘httpUploadProgress’, function(evt) { console.log(evt); }) .send(function(err, data) { console.log(err, data) });
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Try setting the accessKeyId and secretAccessKey in the constructor of the S3 object.
const s3 = new AWS.S3({
endpoint: process.env.SPACES_ENDPOINT,
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
});
s3.upload(...)
The above is working for me.
As a sidenote, I stumbled across this question when I accidentally created a new access token rather than access key.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.