I am trying to put an object to S3 to redirect. I can create the object without problem however in setting the meta data the 301 redirect is not work. The meta data key is created however this is user-defined and not system defined. User-defined meta data starts with x-awz-meta and system defined data is x-amz.
Therefore the system defined key to redirect is x-amz-website-redirect-location however it seems you cannot create this using the JavaScript SDK. When you set the meta data AWS appends user-defined prefix.
With this code.
command = new PutObjectCommand({
Bucket: bucketParams.Bucket,
Key: cliParams.routingRules[0].old_url,
Body: '',
Metadata: {
'x-amz-website-redirect-location': cliParams.routingRules[0].new_url`
}
});
The key created is user defined as x-amz-meta-x-amz-website-redirect-location. If I omit x-amz prefix.
command = new PutObjectCommand({
Bucket: bucketParams.Bucket,
Key: cliParams.routingRules[0].old_url,
Body: '',
Metadata: {
'website-redirect-location': cliParams.routingRules[0].new_url
}
});
The key created is user defined as x-amz-meta-website-redirect-location. The key with x-amz-meta does not 301 redirect.
The key needs to be system defined which is x-amz-website-redirect-location.
Anyone know how to set this ? Thanks
I have tried setting the metadata key to every option. Same result always get a user defined metadata key
This works dont use metadata