Class GetBucketObject
Inheritance
Inherited Members
Namespace: Pulumi.Aws.S3
Assembly: Pulumi.Aws.dll
Syntax
public static class GetBucketObject
Methods
View SourceInvokeAsync(GetBucketObjectArgs, InvokeOptions)
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 (
bodyfield) is available only for objects which have a human-readableContent-Type(text/*andapplication/json). This is to prevent printing unsafe characters and potentially downloading large amount of data which would be thrown away in favour of metadata.
{{% examples %}}
Example Usage
{{% example %}}
The following example retrieves a text object (which must have a Content-Type
value starting with text/) and uses it as the user_data for an EC2 instance:
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var bootstrapScript = Output.Create(Aws.S3.GetBucketObject.InvokeAsync(new Aws.S3.GetBucketObjectArgs
{
Bucket = "ourcorp-deploy-config",
Key = "ec2-bootstrap-script.sh",
}));
var example = new Aws.Ec2.Instance("example", new Aws.Ec2.InstanceArgs
{
Ami = "ami-2757f631",
InstanceType = "t2.micro",
UserData = bootstrapScript.Apply(bootstrapScript => bootstrapScript.Body),
});
}
}
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 version_id
to AWS Lambda for use as a function implementation. More information about
Lambda functions is available in the documentation for
aws.lambda.Function.
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var lambda = Output.Create(Aws.S3.GetBucketObject.InvokeAsync(new Aws.S3.GetBucketObjectArgs
{
Bucket = "ourcorp-lambda-functions",
Key = "hello-world.zip",
}));
var testLambda = new Aws.Lambda.Function("testLambda", new Aws.Lambda.FunctionArgs
{
Handler = "exports.test",
Role = aws_iam_role.Iam_for_lambda.Arn,
S3Bucket = lambda.Apply(lambda => lambda.Bucket),
S3Key = lambda.Apply(lambda => lambda.Key),
S3ObjectVersion = lambda.Apply(lambda => lambda.VersionId),
});
}
}
{{% /example %}} {{% /examples %}}
Declaration
public static Task<GetBucketObjectResult> InvokeAsync(GetBucketObjectArgs args, InvokeOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| GetBucketObjectArgs | args | |
| InvokeOptions | options |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<GetBucketObjectResult> |