-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
S3 Events Not Triggered with Pre-signed URL #945
Description
I am attempting to upload files to Localstack S3 using pre-signed URLs, and then act upon that upload when an S3 Event Notification is received. The events should be written to a Localstack SQS queue and later retrieved by my application. However, I am noticing that uploads performed to a pre-signed URL do not trigger an S3 event.
I am able to create the S3 bucket using the Java SDK:
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(0);
InputStream emptyContent = new ByteArrayInputStream(new byte[0]);
String objName = folderName + (folderName.endsWith(FOLDER_SUFFIX) ? "" : FOLDER_SUFFIX);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objName, emptyContent, metadata);
this.s3Client.putObject(putObjectRequest);
From there, I am able to register my SQS to receive S3 notifications:
BucketNotificationConfiguration notificationConfig = new BucketNotificationConfiguration();
EnumSet<S3Event> eventSet = EnumSet.noneOf(S3Event.class);
eventSet.addAll(Arrays.asList(events));
notificationConfig.addConfiguration("sqsQueueConfig", new QueueConfiguration(queueArn, eventSet));
SetBucketNotificationConfigurationRequest notificationReq = new SetBucketNotificationConfigurationRequest(bucketName, notificationConfig);
this.s3Client.setBucketNotificationConfiguration(notificationReq);
I am able to upload a file from the command line successfully, using the AWS CLI:
aws --endpoint-url=http://localhost:4572 s3 cp myFile.xml s3://reports/myFile.xml
Using the AWS CLI, I am able to see the appropriate S3 Event written to the SQS queue:
aws --endpoint-url=http://localhost:4576 sqs receive-message --queue-url http://localhost:4576/queue/report-processing-queue --region us-east-1
All of this works as expected. I can then generate an S3 pre-signed URL using the Java SDK:
Date expiration = Calendar.getInstance().getTime();
expiration.setTime(expirationTimeMillis);
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey) .withMethod(httpMethod).withExpiration(expiration);
URL url = this.s3Client.generatePresignedUrl(generatePresignedUrlRequest);
However, when I upload a file using an HTTP PUT (either through Java or using curl on the command line) the upload is successful, but I do not see any S3 Events written to the SQS queue. I am able to confirm that the upload was successful using the AWS CLI:
aws --endpoint-url=http://localhost:4572 s3 ls s3://reports/
My expectation is that when I file is uploaded -- regardless of whether it is done using the CLI or a pre-signed URL -- I should see an S3 Event written to the SQS queue. Is this understanding flawed? Or is this a bug within localstack?