https://pulumi.com logo
#general
Title
# general
f

faint-application-2746

10/04/2018, 8:16 PM
Hi, how do I use an existing S3 bucket?
const bucket = new cloud.Bucket("<http://contextubot.net|contextubot.net>", { protect: true });
creates a new one with some random string 😕
c

creamy-potato-29402

10/04/2018, 9:00 PM
@faint-application-2746 that is on purpose
you mean the name, right?
The name gets an auto-suffix so that you can deploy your app multiple times.
Also so that there aren’t name collisions generally.
f

faint-application-2746

10/04/2018, 9:21 PM
Yeah, I understand that but sometimes a S3 bucket is fixed as name as other things write to it and it might even have pre-existing data
same behaviour is in serverless framework but they have serverless-plugin-existing-s3 to deal with that
b

bitter-oil-46081

10/04/2018, 9:31 PM
I think if you want to use an existing S3 bucket, you can't use the cloud abstraction directly, today. You could use the get method on aws.s3.Bucket to retrieve an existing bucket, but you would unfortunately not get the nice
on*
style methods. I think that some of the stuff @lemon-spoon-91807 is working on will make it easy to take an existing S3 bucket and then add handlers to it, similar to if how you created a
cloud.Bucket
directly.
l

lemon-spoon-91807

10/04/2018, 9:34 PM
Here's how it will work RSN (i believe when our next release is)
1. You'll include
import * as aws from "@pulumi/aws"
2.
const bucket = aws.s3.Bucket.get("yourbucketid")
❤️ 1
That will give you the real bucket resource.
if you want to do things like listen for events, you can do:
bucket.onObjectCreated(...)
.
👍🏻 1