0

I am trying to import an existing S3 object into Pulumi. This is my current attempt (using Python):

bucket = s3.Bucket('test-bucket',
               bucket='test-bucket')
file = s3.BucketObject('file.txt',
                   bucket=bucket,
                   key='temp/file.txt',
                   opts=ResourceOptions(import_='temp/file.txt'))

With that config, I am getting the following error:

Diagnostics:
  aws:s3:BucketObject (file.txt):
    error: Preview failed: refreshing urn:pulumi:dev::quickstart::aws:s3/bucketObject:BucketObject::file.txt: 1 error occurred:
        * InvalidParameter: 2 validation error(s) found.
    - minimum field size of 1, HeadObjectInput.Bucket.
    - minimum field size of 1, HeadObjectInput.Key.

I could not find any mention of a HeadObjectInput in the reference documentation.

What parameters should I pass to BucketObject() so that the S3 object is imported in Pulumi?

My final goal here is to use Pulumi to delete an existing object from an S3 bucket. Is there any other way for achieving this?

2 Answers2

1

Currently, the Pulumi aws provider is built on the terraform aws provider. So, I tried importing an S3 bucket and S3 bucket object in terraform. Although the bucket imports in terraform (and Pulumi), terraform throws an error:

Error: resource aws_s3_bucket_object doesn't support import

Therefore, the Pulumi provider (at this time) does not support it either.

Mitch G
  • 196
  • 1
0

If you are indeed trying to import an existing bucket and/or object for Pulumi to manage as part of the stack, this page may help: https://www.pulumi.com/docs/guides/adopting/import/

If you just want to get information about an existing bucket and/or object, then there are get functions available: https://www.pulumi.com/docs/reference/pkg/aws/s3/#functions

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mitch G
  • 196
  • 1
  • Thanks, but I actually want to have the existing S3 object managed by Pulumi so I can delete it. As I mentioned in the question, I have already tried the import approach without success. The functions can only be used to get info about an object (as you mentioned), not to change it. How can I actually change/delete an existing S3 object with Pulumi? – Alexandru Cojocaru Oct 08 '20 at 14:09
  • Yeah sorry, I missed that when I looked at your code the first time. The root cause is explain in the second answer below. But, depending on the use-case, though, you could use the getBucketObjects() function and then use the python AWS SDK to manipulate the objects accordingly. – Mitch G Oct 15 '20 at 18:13