/
getObject.go
348 lines (308 loc) · 16.1 KB
/
getObject.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
// Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
package s3
import (
"context"
"reflect"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// The S3 object data source allows access to the metadata and
// _optionally_ (see below) content of an object stored inside S3 bucket.
//
// > **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.
//
// ## Example Usage
//
// The following example retrieves a text object (which must have a `Content-Type`
// value starting with `text/`) and uses it as the `userData` for an EC2 instance:
//
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ec2"
// "github.com/pulumi/pulumi-aws/sdk/v5/go/aws/s3"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// bootstrapScript, err := s3.GetObject(ctx, &s3.GetObjectArgs{
// Bucket: "ourcorp-deploy-config",
// Key: "ec2-bootstrap-script.sh",
// }, nil)
// if err != nil {
// return err
// }
// _, err = ec2.NewInstance(ctx, "example", &ec2.InstanceArgs{
// InstanceType: pulumi.String("t2.micro"),
// Ami: pulumi.String("ami-2757f631"),
// UserData: *pulumi.String(bootstrapScript.Body),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
//
// The following, more-complex example retrieves only the metadata for a zip
// file stored in S3, which is then used to pass the most recent `versionId`
// to AWS Lambda for use as a function implementation. More information about
// Lambda functions is available in the documentation for
// `lambda.Function`.
//
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-aws/sdk/v5/go/aws"
// "github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lambda"
// "github.com/pulumi/pulumi-aws/sdk/v5/go/aws/s3"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// lambda, err := s3.GetObject(ctx, &s3.GetObjectArgs{
// Bucket: "ourcorp-lambda-functions",
// Key: "hello-world.zip",
// }, nil)
// if err != nil {
// return err
// }
// _, err = lambda.NewFunction(ctx, "testLambda", &lambda.FunctionArgs{
// S3Bucket: *pulumi.String(lambda.Bucket),
// S3Key: *pulumi.String(lambda.Key),
// S3ObjectVersion: *pulumi.String(lambda.VersionId),
// Role: pulumi.Any(aws_iam_role.Iam_for_lambda.Arn),
// Handler: pulumi.String("exports.test"),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
func GetObject(ctx *pulumi.Context, args *GetObjectArgs, opts ...pulumi.InvokeOption) (*GetObjectResult, error) {
var rv GetObjectResult
err := ctx.Invoke("aws:s3/getObject:getObject", args, &rv, opts...)
if err != nil {
return nil, err
}
return &rv, nil
}
// A collection of arguments for invoking getObject.
type GetObjectArgs struct {
// 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
Bucket string `pulumi:"bucket"`
// Full path to the object inside the bucket
Key string `pulumi:"key"`
Range *string `pulumi:"range"`
// Map of tags assigned to the object.
Tags map[string]string `pulumi:"tags"`
// Specific version ID of the object returned (defaults to latest version)
VersionId *string `pulumi:"versionId"`
}
// A collection of values returned by getObject.
type GetObjectResult struct {
// Object data (see **limitations above** to understand cases in which this field is actually available)
Body string `pulumi:"body"`
Bucket string `pulumi:"bucket"`
// (Optional) Whether or not to use [Amazon S3 Bucket Keys](https://docs.aws.amazon.com/AmazonS3/latest/dev/bucket-key.html) for SSE-KMS.
BucketKeyEnabled bool `pulumi:"bucketKeyEnabled"`
// Caching behavior along the request/reply chain.
CacheControl string `pulumi:"cacheControl"`
// Presentational information for the object.
ContentDisposition string `pulumi:"contentDisposition"`
// 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.
ContentEncoding string `pulumi:"contentEncoding"`
// Language the content is in.
ContentLanguage string `pulumi:"contentLanguage"`
// Size of the body in bytes.
ContentLength int `pulumi:"contentLength"`
// Standard MIME type describing the format of the object data.
ContentType string `pulumi:"contentType"`
// [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)
Etag string `pulumi:"etag"`
// 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.
Expiration string `pulumi:"expiration"`
// Date and time at which the object is no longer cacheable.
Expires string `pulumi:"expires"`
// The provider-assigned unique ID for this managed resource.
Id string `pulumi:"id"`
Key string `pulumi:"key"`
// Last modified date of the object in RFC1123 format (e.g., `Mon, 02 Jan 2006 15:04:05 MST`)
LastModified string `pulumi:"lastModified"`
// Map of metadata stored with the object in S3
Metadata map[string]string `pulumi:"metadata"`
// 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.
ObjectLockLegalHoldStatus string `pulumi:"objectLockLegalHoldStatus"`
// 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.
ObjectLockMode string `pulumi:"objectLockMode"`
// The date and time when this object's object lock will expire.
ObjectLockRetainUntilDate string `pulumi:"objectLockRetainUntilDate"`
Range *string `pulumi:"range"`
// 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.
ServerSideEncryption string `pulumi:"serverSideEncryption"`
// If present, specifies the ID of the Key Management Service (KMS) master encryption key that was used for the object.
SseKmsKeyId string `pulumi:"sseKmsKeyId"`
// [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.
StorageClass string `pulumi:"storageClass"`
// Map of tags assigned to the object.
Tags map[string]string `pulumi:"tags"`
// Latest version ID of the object returned.
VersionId string `pulumi:"versionId"`
// 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.
WebsiteRedirectLocation string `pulumi:"websiteRedirectLocation"`
}
func GetObjectOutput(ctx *pulumi.Context, args GetObjectOutputArgs, opts ...pulumi.InvokeOption) GetObjectResultOutput {
return pulumi.ToOutputWithContext(context.Background(), args).
ApplyT(func(v interface{}) (GetObjectResult, error) {
args := v.(GetObjectArgs)
r, err := GetObject(ctx, &args, opts...)
var s GetObjectResult
if r != nil {
s = *r
}
return s, err
}).(GetObjectResultOutput)
}
// A collection of arguments for invoking getObject.
type GetObjectOutputArgs struct {
// 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
Bucket pulumi.StringInput `pulumi:"bucket"`
// Full path to the object inside the bucket
Key pulumi.StringInput `pulumi:"key"`
Range pulumi.StringPtrInput `pulumi:"range"`
// Map of tags assigned to the object.
Tags pulumi.StringMapInput `pulumi:"tags"`
// Specific version ID of the object returned (defaults to latest version)
VersionId pulumi.StringPtrInput `pulumi:"versionId"`
}
func (GetObjectOutputArgs) ElementType() reflect.Type {
return reflect.TypeOf((*GetObjectArgs)(nil)).Elem()
}
// A collection of values returned by getObject.
type GetObjectResultOutput struct{ *pulumi.OutputState }
func (GetObjectResultOutput) ElementType() reflect.Type {
return reflect.TypeOf((*GetObjectResult)(nil)).Elem()
}
func (o GetObjectResultOutput) ToGetObjectResultOutput() GetObjectResultOutput {
return o
}
func (o GetObjectResultOutput) ToGetObjectResultOutputWithContext(ctx context.Context) GetObjectResultOutput {
return o
}
// Object data (see **limitations above** to understand cases in which this field is actually available)
func (o GetObjectResultOutput) Body() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.Body }).(pulumi.StringOutput)
}
func (o GetObjectResultOutput) Bucket() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.Bucket }).(pulumi.StringOutput)
}
// (Optional) Whether or not to use [Amazon S3 Bucket Keys](https://docs.aws.amazon.com/AmazonS3/latest/dev/bucket-key.html) for SSE-KMS.
func (o GetObjectResultOutput) BucketKeyEnabled() pulumi.BoolOutput {
return o.ApplyT(func(v GetObjectResult) bool { return v.BucketKeyEnabled }).(pulumi.BoolOutput)
}
// Caching behavior along the request/reply chain.
func (o GetObjectResultOutput) CacheControl() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.CacheControl }).(pulumi.StringOutput)
}
// Presentational information for the object.
func (o GetObjectResultOutput) ContentDisposition() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.ContentDisposition }).(pulumi.StringOutput)
}
// 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.
func (o GetObjectResultOutput) ContentEncoding() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.ContentEncoding }).(pulumi.StringOutput)
}
// Language the content is in.
func (o GetObjectResultOutput) ContentLanguage() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.ContentLanguage }).(pulumi.StringOutput)
}
// Size of the body in bytes.
func (o GetObjectResultOutput) ContentLength() pulumi.IntOutput {
return o.ApplyT(func(v GetObjectResult) int { return v.ContentLength }).(pulumi.IntOutput)
}
// Standard MIME type describing the format of the object data.
func (o GetObjectResultOutput) ContentType() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.ContentType }).(pulumi.StringOutput)
}
// [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)
func (o GetObjectResultOutput) Etag() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.Etag }).(pulumi.StringOutput)
}
// 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.
func (o GetObjectResultOutput) Expiration() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.Expiration }).(pulumi.StringOutput)
}
// Date and time at which the object is no longer cacheable.
func (o GetObjectResultOutput) Expires() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.Expires }).(pulumi.StringOutput)
}
// The provider-assigned unique ID for this managed resource.
func (o GetObjectResultOutput) Id() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.Id }).(pulumi.StringOutput)
}
func (o GetObjectResultOutput) Key() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.Key }).(pulumi.StringOutput)
}
// Last modified date of the object in RFC1123 format (e.g., `Mon, 02 Jan 2006 15:04:05 MST`)
func (o GetObjectResultOutput) LastModified() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.LastModified }).(pulumi.StringOutput)
}
// Map of metadata stored with the object in S3
func (o GetObjectResultOutput) Metadata() pulumi.StringMapOutput {
return o.ApplyT(func(v GetObjectResult) map[string]string { return v.Metadata }).(pulumi.StringMapOutput)
}
// 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.
func (o GetObjectResultOutput) ObjectLockLegalHoldStatus() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.ObjectLockLegalHoldStatus }).(pulumi.StringOutput)
}
// 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.
func (o GetObjectResultOutput) ObjectLockMode() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.ObjectLockMode }).(pulumi.StringOutput)
}
// The date and time when this object's object lock will expire.
func (o GetObjectResultOutput) ObjectLockRetainUntilDate() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.ObjectLockRetainUntilDate }).(pulumi.StringOutput)
}
func (o GetObjectResultOutput) Range() pulumi.StringPtrOutput {
return o.ApplyT(func(v GetObjectResult) *string { return v.Range }).(pulumi.StringPtrOutput)
}
// 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.
func (o GetObjectResultOutput) ServerSideEncryption() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.ServerSideEncryption }).(pulumi.StringOutput)
}
// If present, specifies the ID of the Key Management Service (KMS) master encryption key that was used for the object.
func (o GetObjectResultOutput) SseKmsKeyId() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.SseKmsKeyId }).(pulumi.StringOutput)
}
// [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.
func (o GetObjectResultOutput) StorageClass() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.StorageClass }).(pulumi.StringOutput)
}
// Map of tags assigned to the object.
func (o GetObjectResultOutput) Tags() pulumi.StringMapOutput {
return o.ApplyT(func(v GetObjectResult) map[string]string { return v.Tags }).(pulumi.StringMapOutput)
}
// Latest version ID of the object returned.
func (o GetObjectResultOutput) VersionId() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.VersionId }).(pulumi.StringOutput)
}
// 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.
func (o GetObjectResultOutput) WebsiteRedirectLocation() pulumi.StringOutput {
return o.ApplyT(func(v GetObjectResult) string { return v.WebsiteRedirectLocation }).(pulumi.StringOutput)
}
func init() {
pulumi.RegisterOutputType(GetObjectResultOutput{})
}