I am using the @aws-sdk/client-s3
package to use AWS APIs.
I try to upload redirect objects to my bucket using this code:
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
const s3Client = new S3Client({ region: process.env.AWS_REGION });
const putS3Command = new PutObjectCommand({
Bucket: process.env.S3_BUCKET,
Key: hashedUrl,
WebsiteRedirectLocation: validatedRequestBody.url,
});
await s3Client.send(putS3Command);
The command indeed succeeds, and I see the object in the bucket when I browse AWS S3 service:
However, when I try to access the object (using presigned URL), I don’t get redirected, but I just get download file of size 0.
Is there anything wrong with my PutObjectCommand
?
I configured this S3 bucket using Terraform:
module "urls_s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "4.1.0"
acl = "private"
force_destroy = true
attach_policy = true
policy = data.aws_iam_policy_document.urls_s3_policy.json
control_object_ownership = true
object_ownership = "BucketOwnerPreferred"
tags = merge(
var.common_tags,
{
Name = "${var.project}-Client-URLs-S3-Bucket"
Stack = "Backend"
}
)
}