I'm trying to use sst 1.0.0-beta20 to define an S3...
# help
s
I'm trying to use sst 1.0.0-beta20 to define an S3 bucket that triggers a lambda invocation when a file is uploaded. I'm getting an error when using the example in the docs and can't make sense of it
The error
Copy code
Type '{ function: string; events: "object_created"[]; }[]' is not assignable to type 'Record<string, FunctionInlineDefinition | BucketFunctionNotificationProps | Queue | BucketQueueNotificationProps | Topic | BucketTopicNotificationProps>'.
  Index signature for type 'string' is missing in type '{ function: string; events: "object_created"[]; }[]'.ts(2322)
The Bucket creation taken from the docs
Copy code
const bucket = new sst.Bucket(stack, "Bucket", {
      notifications: [
        {
          function: "src/notification.main",
          events: ["object_created"],
        },
      ],
    });
t
We're working through the same issue right now - what I'm seeing is that the
type 'Record<string, ...
bit in the error output means that the expected value for the
events
key has been changed from an array to an object. No guarantees here, but that's what's been working for us with similar errors so far
Of note, the actual keys don't seem to matter - just that the value is an object instead of an array
s
Hmm, not sure I follow (e.g. what that object should look like if not a string)
t
On second look, I think I misread your error. We add our notifications via
bucket.addNotifications(...)
, but based on the changes we had to make, I'd say try something like this:
Copy code
const bucket = new sst.Bucket(stack, "Bucket", {
      notifications: {
        keyThatDoesntMatter: {
          function: "src/notification.main",
          events: ["object_created"],
        },
      },
    });
s
ahh, I'll give that a shot!
looks like that works. weird.... Thank you!
f
@Seth Geoghegan @Tanner Bindrup sorry for the confusion guys, it should be an object, not an array.
@Tanner Bindrup’s snippet is right
Copy code
const bucket = new sst.Bucket(stack, "Bucket", {
  notifications: {
    keyThatDoesntMatter: {
      function: "src/notification.main",
      events: ["object_created"],
    },
  },
});
s
I got it working, thanks for the support!