github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/s3/getObject.go (about) 1 // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT. 2 // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! *** 3 4 package s3 5 6 import ( 7 "context" 8 "reflect" 9 10 "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal" 11 "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 12 ) 13 14 // The S3 object data source allows access to the metadata and 15 // _optionally_ (see below) content of an object stored inside S3 bucket. 16 // 17 // > **Note:** The content of an object (`body` field) is available only for objects which have a human-readable `Content-Type` (`text/*` and `application/json`). This is to prevent printing unsafe characters and potentially downloading large amount of data which would be thrown away in favour of metadata. 18 // 19 // ## Example Usage 20 // 21 // The following example retrieves a text object (which must have a `Content-Type` 22 // value starting with `text/`) and uses it as the `userData` for an EC2 instance: 23 // 24 // <!--Start PulumiCodeChooser --> 25 // ```go 26 // package main 27 // 28 // import ( 29 // 30 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2" 31 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/s3" 32 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 33 // 34 // ) 35 // 36 // func main() { 37 // pulumi.Run(func(ctx *pulumi.Context) error { 38 // bootstrapScript, err := s3.GetObject(ctx, &s3.GetObjectArgs{ 39 // Bucket: "ourcorp-deploy-config", 40 // Key: "ec2-bootstrap-script.sh", 41 // }, nil) 42 // if err != nil { 43 // return err 44 // } 45 // _, err = ec2.NewInstance(ctx, "example", &ec2.InstanceArgs{ 46 // InstanceType: pulumi.String(ec2.InstanceType_T2_Micro), 47 // Ami: pulumi.String("ami-2757f631"), 48 // UserData: pulumi.String(bootstrapScript.Body), 49 // }) 50 // if err != nil { 51 // return err 52 // } 53 // return nil 54 // }) 55 // } 56 // 57 // ``` 58 // <!--End PulumiCodeChooser --> 59 // 60 // The following, more-complex example retrieves only the metadata for a zip 61 // file stored in S3, which is then used to pass the most recent `versionId` 62 // to AWS Lambda for use as a function implementation. More information about 63 // Lambda functions is available in the documentation for 64 // `lambda.Function`. 65 // 66 // <!--Start PulumiCodeChooser --> 67 // ```go 68 // package main 69 // 70 // import ( 71 // 72 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws" 73 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lambda" 74 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/s3" 75 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 76 // 77 // ) 78 // 79 // func main() { 80 // pulumi.Run(func(ctx *pulumi.Context) error { 81 // lambda, err := s3.GetObject(ctx, &s3.GetObjectArgs{ 82 // Bucket: "ourcorp-lambda-functions", 83 // Key: "hello-world.zip", 84 // }, nil) 85 // if err != nil { 86 // return err 87 // } 88 // _, err = lambda.NewFunction(ctx, "test_lambda", &lambda.FunctionArgs{ 89 // S3Bucket: pulumi.String(lambda.Bucket), 90 // S3Key: pulumi.String(lambda.Key), 91 // S3ObjectVersion: pulumi.String(lambda.VersionId), 92 // Name: pulumi.String("lambda_function_name"), 93 // Role: pulumi.Any(iamForLambda.Arn), 94 // Handler: pulumi.String("exports.test"), 95 // }) 96 // if err != nil { 97 // return err 98 // } 99 // return nil 100 // }) 101 // } 102 // 103 // ``` 104 // <!--End PulumiCodeChooser --> 105 func GetObject(ctx *pulumi.Context, args *GetObjectArgs, opts ...pulumi.InvokeOption) (*GetObjectResult, error) { 106 opts = internal.PkgInvokeDefaultOpts(opts) 107 var rv GetObjectResult 108 err := ctx.Invoke("aws:s3/getObject:getObject", args, &rv, opts...) 109 if err != nil { 110 return nil, err 111 } 112 return &rv, nil 113 } 114 115 // A collection of arguments for invoking getObject. 116 type GetObjectArgs struct { 117 // Name of the bucket to read the object from. Alternatively, an [S3 access point](https://docs.aws.amazon.com/AmazonS3/latest/dev/using-access-points.html) ARN can be specified 118 Bucket string `pulumi:"bucket"` 119 // To retrieve the object's checksum, this argument must be `ENABLED`. If you enable `checksumMode` and the object is encrypted with KMS, you must have permission to use the `kms:Decrypt` action. Valid values: `ENABLED` 120 ChecksumMode *string `pulumi:"checksumMode"` 121 // Full path to the object inside the bucket 122 Key string `pulumi:"key"` 123 Range *string `pulumi:"range"` 124 // Map of tags assigned to the object. 125 Tags map[string]string `pulumi:"tags"` 126 // Specific version ID of the object returned (defaults to latest version) 127 VersionId *string `pulumi:"versionId"` 128 } 129 130 // A collection of values returned by getObject. 131 type GetObjectResult struct { 132 // ARN of the object. 133 Arn string `pulumi:"arn"` 134 // Object data (see **limitations above** to understand cases in which this field is actually available) 135 Body string `pulumi:"body"` 136 Bucket string `pulumi:"bucket"` 137 // (Optional) Whether or not to use [Amazon S3 Bucket Keys](https://docs.aws.amazon.com/AmazonS3/latest/dev/bucket-key.html) for SSE-KMS. 138 BucketKeyEnabled bool `pulumi:"bucketKeyEnabled"` 139 // Caching behavior along the request/reply chain. 140 CacheControl string `pulumi:"cacheControl"` 141 // The base64-encoded, 32-bit CRC32 checksum of the object. 142 ChecksumCrc32 string `pulumi:"checksumCrc32"` 143 // The base64-encoded, 32-bit CRC32C checksum of the object. 144 ChecksumCrc32c string `pulumi:"checksumCrc32c"` 145 ChecksumMode *string `pulumi:"checksumMode"` 146 // The base64-encoded, 160-bit SHA-1 digest of the object. 147 ChecksumSha1 string `pulumi:"checksumSha1"` 148 // The base64-encoded, 256-bit SHA-256 digest of the object. 149 ChecksumSha256 string `pulumi:"checksumSha256"` 150 // Presentational information for the object. 151 ContentDisposition string `pulumi:"contentDisposition"` 152 // What content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. 153 ContentEncoding string `pulumi:"contentEncoding"` 154 // Language the content is in. 155 ContentLanguage string `pulumi:"contentLanguage"` 156 // Size of the body in bytes. 157 ContentLength int `pulumi:"contentLength"` 158 // Standard MIME type describing the format of the object data. 159 ContentType string `pulumi:"contentType"` 160 // [ETag](https://en.wikipedia.org/wiki/HTTP_ETag) generated for the object (an MD5 sum of the object content in case it's not encrypted) 161 Etag string `pulumi:"etag"` 162 // If the object expiration is configured (see [object lifecycle management](http://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html)), the field includes this header. It includes the expiry-date and rule-id key value pairs providing object expiration information. The value of the rule-id is URL encoded. 163 Expiration string `pulumi:"expiration"` 164 // Date and time at which the object is no longer cacheable. 165 Expires string `pulumi:"expires"` 166 // The provider-assigned unique ID for this managed resource. 167 Id string `pulumi:"id"` 168 Key string `pulumi:"key"` 169 // Last modified date of the object in RFC1123 format (e.g., `Mon, 02 Jan 2006 15:04:05 MST`) 170 LastModified string `pulumi:"lastModified"` 171 // Map of metadata stored with the object in S3. Keys are always returned in lowercase. 172 Metadata map[string]string `pulumi:"metadata"` 173 // Indicates whether this object has an active [legal hold](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock-overview.html#object-lock-legal-holds). This field is only returned if you have permission to view an object's legal hold status. 174 ObjectLockLegalHoldStatus string `pulumi:"objectLockLegalHoldStatus"` 175 // Object lock [retention mode](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock-overview.html#object-lock-retention-modes) currently in place for this object. 176 ObjectLockMode string `pulumi:"objectLockMode"` 177 // The date and time when this object's object lock will expire. 178 ObjectLockRetainUntilDate string `pulumi:"objectLockRetainUntilDate"` 179 Range *string `pulumi:"range"` 180 // If the object is stored using server-side encryption (KMS or Amazon S3-managed encryption key), this field includes the chosen encryption and algorithm used. 181 ServerSideEncryption string `pulumi:"serverSideEncryption"` 182 // If present, specifies the ID of the Key Management Service (KMS) master encryption key that was used for the object. 183 SseKmsKeyId string `pulumi:"sseKmsKeyId"` 184 // [Storage class](http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html) information of the object. Available for all objects except for `Standard` storage class objects. 185 StorageClass string `pulumi:"storageClass"` 186 // Map of tags assigned to the object. 187 Tags map[string]string `pulumi:"tags"` 188 // Latest version ID of the object returned. 189 VersionId string `pulumi:"versionId"` 190 // If the bucket is configured as a website, redirects requests for this object to another object in the same bucket or to an external URL. Amazon S3 stores the value of this header in the object metadata. 191 WebsiteRedirectLocation string `pulumi:"websiteRedirectLocation"` 192 } 193 194 func GetObjectOutput(ctx *pulumi.Context, args GetObjectOutputArgs, opts ...pulumi.InvokeOption) GetObjectResultOutput { 195 return pulumi.ToOutputWithContext(context.Background(), args). 196 ApplyT(func(v interface{}) (GetObjectResult, error) { 197 args := v.(GetObjectArgs) 198 r, err := GetObject(ctx, &args, opts...) 199 var s GetObjectResult 200 if r != nil { 201 s = *r 202 } 203 return s, err 204 }).(GetObjectResultOutput) 205 } 206 207 // A collection of arguments for invoking getObject. 208 type GetObjectOutputArgs struct { 209 // Name of the bucket to read the object from. Alternatively, an [S3 access point](https://docs.aws.amazon.com/AmazonS3/latest/dev/using-access-points.html) ARN can be specified 210 Bucket pulumi.StringInput `pulumi:"bucket"` 211 // To retrieve the object's checksum, this argument must be `ENABLED`. If you enable `checksumMode` and the object is encrypted with KMS, you must have permission to use the `kms:Decrypt` action. Valid values: `ENABLED` 212 ChecksumMode pulumi.StringPtrInput `pulumi:"checksumMode"` 213 // Full path to the object inside the bucket 214 Key pulumi.StringInput `pulumi:"key"` 215 Range pulumi.StringPtrInput `pulumi:"range"` 216 // Map of tags assigned to the object. 217 Tags pulumi.StringMapInput `pulumi:"tags"` 218 // Specific version ID of the object returned (defaults to latest version) 219 VersionId pulumi.StringPtrInput `pulumi:"versionId"` 220 } 221 222 func (GetObjectOutputArgs) ElementType() reflect.Type { 223 return reflect.TypeOf((*GetObjectArgs)(nil)).Elem() 224 } 225 226 // A collection of values returned by getObject. 227 type GetObjectResultOutput struct{ *pulumi.OutputState } 228 229 func (GetObjectResultOutput) ElementType() reflect.Type { 230 return reflect.TypeOf((*GetObjectResult)(nil)).Elem() 231 } 232 233 func (o GetObjectResultOutput) ToGetObjectResultOutput() GetObjectResultOutput { 234 return o 235 } 236 237 func (o GetObjectResultOutput) ToGetObjectResultOutputWithContext(ctx context.Context) GetObjectResultOutput { 238 return o 239 } 240 241 // ARN of the object. 242 func (o GetObjectResultOutput) Arn() pulumi.StringOutput { 243 return o.ApplyT(func(v GetObjectResult) string { return v.Arn }).(pulumi.StringOutput) 244 } 245 246 // Object data (see **limitations above** to understand cases in which this field is actually available) 247 func (o GetObjectResultOutput) Body() pulumi.StringOutput { 248 return o.ApplyT(func(v GetObjectResult) string { return v.Body }).(pulumi.StringOutput) 249 } 250 251 func (o GetObjectResultOutput) Bucket() pulumi.StringOutput { 252 return o.ApplyT(func(v GetObjectResult) string { return v.Bucket }).(pulumi.StringOutput) 253 } 254 255 // (Optional) Whether or not to use [Amazon S3 Bucket Keys](https://docs.aws.amazon.com/AmazonS3/latest/dev/bucket-key.html) for SSE-KMS. 256 func (o GetObjectResultOutput) BucketKeyEnabled() pulumi.BoolOutput { 257 return o.ApplyT(func(v GetObjectResult) bool { return v.BucketKeyEnabled }).(pulumi.BoolOutput) 258 } 259 260 // Caching behavior along the request/reply chain. 261 func (o GetObjectResultOutput) CacheControl() pulumi.StringOutput { 262 return o.ApplyT(func(v GetObjectResult) string { return v.CacheControl }).(pulumi.StringOutput) 263 } 264 265 // The base64-encoded, 32-bit CRC32 checksum of the object. 266 func (o GetObjectResultOutput) ChecksumCrc32() pulumi.StringOutput { 267 return o.ApplyT(func(v GetObjectResult) string { return v.ChecksumCrc32 }).(pulumi.StringOutput) 268 } 269 270 // The base64-encoded, 32-bit CRC32C checksum of the object. 271 func (o GetObjectResultOutput) ChecksumCrc32c() pulumi.StringOutput { 272 return o.ApplyT(func(v GetObjectResult) string { return v.ChecksumCrc32c }).(pulumi.StringOutput) 273 } 274 275 func (o GetObjectResultOutput) ChecksumMode() pulumi.StringPtrOutput { 276 return o.ApplyT(func(v GetObjectResult) *string { return v.ChecksumMode }).(pulumi.StringPtrOutput) 277 } 278 279 // The base64-encoded, 160-bit SHA-1 digest of the object. 280 func (o GetObjectResultOutput) ChecksumSha1() pulumi.StringOutput { 281 return o.ApplyT(func(v GetObjectResult) string { return v.ChecksumSha1 }).(pulumi.StringOutput) 282 } 283 284 // The base64-encoded, 256-bit SHA-256 digest of the object. 285 func (o GetObjectResultOutput) ChecksumSha256() pulumi.StringOutput { 286 return o.ApplyT(func(v GetObjectResult) string { return v.ChecksumSha256 }).(pulumi.StringOutput) 287 } 288 289 // Presentational information for the object. 290 func (o GetObjectResultOutput) ContentDisposition() pulumi.StringOutput { 291 return o.ApplyT(func(v GetObjectResult) string { return v.ContentDisposition }).(pulumi.StringOutput) 292 } 293 294 // What content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. 295 func (o GetObjectResultOutput) ContentEncoding() pulumi.StringOutput { 296 return o.ApplyT(func(v GetObjectResult) string { return v.ContentEncoding }).(pulumi.StringOutput) 297 } 298 299 // Language the content is in. 300 func (o GetObjectResultOutput) ContentLanguage() pulumi.StringOutput { 301 return o.ApplyT(func(v GetObjectResult) string { return v.ContentLanguage }).(pulumi.StringOutput) 302 } 303 304 // Size of the body in bytes. 305 func (o GetObjectResultOutput) ContentLength() pulumi.IntOutput { 306 return o.ApplyT(func(v GetObjectResult) int { return v.ContentLength }).(pulumi.IntOutput) 307 } 308 309 // Standard MIME type describing the format of the object data. 310 func (o GetObjectResultOutput) ContentType() pulumi.StringOutput { 311 return o.ApplyT(func(v GetObjectResult) string { return v.ContentType }).(pulumi.StringOutput) 312 } 313 314 // [ETag](https://en.wikipedia.org/wiki/HTTP_ETag) generated for the object (an MD5 sum of the object content in case it's not encrypted) 315 func (o GetObjectResultOutput) Etag() pulumi.StringOutput { 316 return o.ApplyT(func(v GetObjectResult) string { return v.Etag }).(pulumi.StringOutput) 317 } 318 319 // If the object expiration is configured (see [object lifecycle management](http://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html)), the field includes this header. It includes the expiry-date and rule-id key value pairs providing object expiration information. The value of the rule-id is URL encoded. 320 func (o GetObjectResultOutput) Expiration() pulumi.StringOutput { 321 return o.ApplyT(func(v GetObjectResult) string { return v.Expiration }).(pulumi.StringOutput) 322 } 323 324 // Date and time at which the object is no longer cacheable. 325 func (o GetObjectResultOutput) Expires() pulumi.StringOutput { 326 return o.ApplyT(func(v GetObjectResult) string { return v.Expires }).(pulumi.StringOutput) 327 } 328 329 // The provider-assigned unique ID for this managed resource. 330 func (o GetObjectResultOutput) Id() pulumi.StringOutput { 331 return o.ApplyT(func(v GetObjectResult) string { return v.Id }).(pulumi.StringOutput) 332 } 333 334 func (o GetObjectResultOutput) Key() pulumi.StringOutput { 335 return o.ApplyT(func(v GetObjectResult) string { return v.Key }).(pulumi.StringOutput) 336 } 337 338 // Last modified date of the object in RFC1123 format (e.g., `Mon, 02 Jan 2006 15:04:05 MST`) 339 func (o GetObjectResultOutput) LastModified() pulumi.StringOutput { 340 return o.ApplyT(func(v GetObjectResult) string { return v.LastModified }).(pulumi.StringOutput) 341 } 342 343 // Map of metadata stored with the object in S3. Keys are always returned in lowercase. 344 func (o GetObjectResultOutput) Metadata() pulumi.StringMapOutput { 345 return o.ApplyT(func(v GetObjectResult) map[string]string { return v.Metadata }).(pulumi.StringMapOutput) 346 } 347 348 // Indicates whether this object has an active [legal hold](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock-overview.html#object-lock-legal-holds). This field is only returned if you have permission to view an object's legal hold status. 349 func (o GetObjectResultOutput) ObjectLockLegalHoldStatus() pulumi.StringOutput { 350 return o.ApplyT(func(v GetObjectResult) string { return v.ObjectLockLegalHoldStatus }).(pulumi.StringOutput) 351 } 352 353 // Object lock [retention mode](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock-overview.html#object-lock-retention-modes) currently in place for this object. 354 func (o GetObjectResultOutput) ObjectLockMode() pulumi.StringOutput { 355 return o.ApplyT(func(v GetObjectResult) string { return v.ObjectLockMode }).(pulumi.StringOutput) 356 } 357 358 // The date and time when this object's object lock will expire. 359 func (o GetObjectResultOutput) ObjectLockRetainUntilDate() pulumi.StringOutput { 360 return o.ApplyT(func(v GetObjectResult) string { return v.ObjectLockRetainUntilDate }).(pulumi.StringOutput) 361 } 362 363 func (o GetObjectResultOutput) Range() pulumi.StringPtrOutput { 364 return o.ApplyT(func(v GetObjectResult) *string { return v.Range }).(pulumi.StringPtrOutput) 365 } 366 367 // If the object is stored using server-side encryption (KMS or Amazon S3-managed encryption key), this field includes the chosen encryption and algorithm used. 368 func (o GetObjectResultOutput) ServerSideEncryption() pulumi.StringOutput { 369 return o.ApplyT(func(v GetObjectResult) string { return v.ServerSideEncryption }).(pulumi.StringOutput) 370 } 371 372 // If present, specifies the ID of the Key Management Service (KMS) master encryption key that was used for the object. 373 func (o GetObjectResultOutput) SseKmsKeyId() pulumi.StringOutput { 374 return o.ApplyT(func(v GetObjectResult) string { return v.SseKmsKeyId }).(pulumi.StringOutput) 375 } 376 377 // [Storage class](http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html) information of the object. Available for all objects except for `Standard` storage class objects. 378 func (o GetObjectResultOutput) StorageClass() pulumi.StringOutput { 379 return o.ApplyT(func(v GetObjectResult) string { return v.StorageClass }).(pulumi.StringOutput) 380 } 381 382 // Map of tags assigned to the object. 383 func (o GetObjectResultOutput) Tags() pulumi.StringMapOutput { 384 return o.ApplyT(func(v GetObjectResult) map[string]string { return v.Tags }).(pulumi.StringMapOutput) 385 } 386 387 // Latest version ID of the object returned. 388 func (o GetObjectResultOutput) VersionId() pulumi.StringOutput { 389 return o.ApplyT(func(v GetObjectResult) string { return v.VersionId }).(pulumi.StringOutput) 390 } 391 392 // If the bucket is configured as a website, redirects requests for this object to another object in the same bucket or to an external URL. Amazon S3 stores the value of this header in the object metadata. 393 func (o GetObjectResultOutput) WebsiteRedirectLocation() pulumi.StringOutput { 394 return o.ApplyT(func(v GetObjectResult) string { return v.WebsiteRedirectLocation }).(pulumi.StringOutput) 395 } 396 397 func init() { 398 pulumi.RegisterOutputType(GetObjectResultOutput{}) 399 }