To bottom line what I am trying to accomplish, I am trying to copy a folder in order to add tags to that folder, according to the docs evidently it's impossible to add (or edit tags) on folders and objects that already exist. In my app I need to delete folders full of attachments after a certain status of a record is set. So when the status changes in my app I need to update the tag in S3 so that the S3 management rules can kick in after 30 days and delete the folder.
I have read the javascript related post here, but I don't believe my issue is related
I am able to successfully make a folder using s3.putObject
await s3.putObject({
Bucket: process.env.BUCKET,
Key: '611d308b6ef5e4066e047824/'
}).promise()
I am able to confirm that the folder was created using s3.listObjectsV2
const data = await s3.listObjectsV2({
Bucket: process.env.BUCKET,
Delimiter: '/',
Prefix: '611d308b6ef5e4066e047824' // <-- no slash
}).promise()
console.log(data)
// {
// IsTruncated: false,
// Contents: [ [Object] ],
// Name: '...', // <-- bucket name
// Prefix: '611d308b6ef5e4066e047824/',
// Delimiter: '/',
// MaxKeys: 1000,
// CommonPrefixes: [],
// KeyCount: 1
// }
I am also able to confirm the files are uploaded (im using multer/multer-s3 in express for this), but using s3.listObjectsV2
they are visible under Contents
const data = await s3.listObjectsV2({
Bucket: process.env.BUCKET,
Delimiter: '/',
Prefix: '611d308b6ef5e4066e047824/' // <-- with a slash
}).promise()
console.log(data)
// {
// IsTruncated: false,
// Contents: [
// {
// Key: '611d308b6ef5e4066e047824/p19179.jpg',
// LastModified: '2021-09-02T21:06:09.000Z',
// ETag: '\"53e6ca3e139f171d486527bd7bcd16d4\"',
// Size: 10154,
// StorageClass: 'STANDARD'
// }
// ],
// Name: '...', // <-- bucket name
// Prefix: '611d308b6ef5e4066e047824/',
// Delimiter: '/',
// MaxKeys: 10,
// CommonPrefixes: [],
// KeyCount: 1,
// StartAfter: '611d308b6ef5e4066e047824/0'
// }
The error appears when I try to run s3.copyObject
, im adding tags here because Multer and Multer-S3 do not support adding tags, so it has to be accomplished via s3.copyObject
after the fact
const data = await s3.copyObject({
Key: '611d308b6ef5e4066e047824/',
// Key: encodeURI('611d308b6ef5e4066e047824/'), <-- i have also tried this unsuccessfully
// Key: '611d308b6ef5e4066e047824', <-- and this
Tagging: 'myKey=myVal',
Metadata: {
myKey: 'myVal'
},
CopySource: `${process.env.BUCKET}/611d308b6ef5e4066e047824/`,
// CopySource: `${process.env.BUCKET}/611d308b6ef5e4066e047824`, // <-- this does not work either
Bucket: process.env.BUCKET,
MetadataDirective: 'REPLACE',
TaggingDirective: 'REPLACE'
}).promise()
below is my error stack from my application
app:lib:aws:s3:folders:updateOptions FATAL The specified key does not exist. +0ms
app:lib:aws:s3:folders:updateOptions FATAL NoSuchKey: The specified key does not exist.
app:lib:aws:s3:folders:updateOptions at Request.extractError (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/services/s3.js:714:35)
app:lib:aws:s3:folders:updateOptions at Request.callListeners (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
app:lib:aws:s3:folders:updateOptions at Request.emit (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
app:lib:aws:s3:folders:updateOptions at Request.emit (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/request.js:688:14)
app:lib:aws:s3:folders:updateOptions at Request.transition (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/request.js:22:10)
app:lib:aws:s3:folders:updateOptions at AcceptorStateMachine.runTo (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/state_machine.js:14:12)
app:lib:aws:s3:folders:updateOptions at /Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/state_machine.js:26:10
app:lib:aws:s3:folders:updateOptions at Request.<anonymous> (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/request.js:38:9)
app:lib:aws:s3:folders:updateOptions at Request.<anonymous> (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/request.js:690:12)
app:lib:aws:s3:folders:updateOptions at Request.callListeners (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
app:lib:aws:s3:folders:updateOptions at Request.emit (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
app:lib:aws:s3:folders:updateOptions at Request.emit (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/request.js:688:14)
app:lib:aws:s3:folders:updateOptions at Request.transition (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/request.js:22:10)
app:lib:aws:s3:folders:updateOptions at AcceptorStateMachine.runTo (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/state_machine.js:14:12)
app:lib:aws:s3:folders:updateOptions at /Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/state_machine.js:26:10
app:lib:aws:s3:folders:updateOptions at Request.<anonymous> (/Users/aronlilland/Documents/dev/controlair/fileManager/node_modules/aws-sdk/lib/request.js:38:9) +0ms
So this error is incorrect, it does exist - whats more, I am able to successfully run s3.copyObject
on some other test records, but the information above is representative of my folder names with live data, I have no idea what to do next ♂️