localstack icon indicating copy to clipboard operation
localstack copied to clipboard

S3 Events Not Triggered with Pre-signed URL

Open TheGeekPharaoh opened this issue 8 years ago • 6 comments

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?

TheGeekPharaoh avatar Sep 28 '18 17:09 TheGeekPharaoh

I have verified that when using the real SQS/S3 these events are generated as expected when uploading using a pre-signed URL. They are not when using Localstack SQS/S3.

TheGeekPharaoh avatar Nov 07 '18 16:11 TheGeekPharaoh

Facing same issue.

jskrnbindra avatar Jan 04 '19 11:01 jskrnbindra

Facing same issue.

coolcodr avatar Jan 30 '19 03:01 coolcodr

Facing same issue

joshhayes-sheen-wf avatar Mar 27 '19 19:03 joshhayes-sheen-wf

Facing same issue.

andrebask avatar Sep 23 '19 14:09 andrebask

Thanks for reporting - should be fixed in #1639

whummer avatar Oct 10 '19 15:10 whummer