getObject

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 user_data for an EC2 instance:

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.s3.S3Functions;
import com.pulumi.aws.s3.inputs.GetObjectArgs;
import com.pulumi.aws.ec2.Instance;
import com.pulumi.aws.ec2.InstanceArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var bootstrapScript = S3Functions.getObject(GetObjectArgs.builder()
.bucket("ourcorp-deploy-config")
.key("ec2-bootstrap-script.sh")
.build());
var example = new Instance("example", InstanceArgs.builder()
.instanceType("t2.micro")
.ami("ami-2757f631")
.userData(bootstrapScript.applyValue(getObjectResult -> getObjectResult.body()))
.build());
}
}

Return

A collection of values returned by getObject. */

Parameters

argument

A collection of arguments for invoking getObject.


suspend fun getObject(bucket: String, key: String, range: String? = null, tags: Map<String, String>? = null, versionId: String? = null): GetObjectResult

Return

A collection of values returned by getObject.

Parameters

bucket

Name of the bucket to read the object from. Alternatively, an S3 access point ARN can be specified

key

Full path to the object inside the bucket

range
tags

Map of tags assigned to the object.

versionId

Specific version ID of the object returned (defaults to latest version)

See also


suspend fun getObject(argument: suspend GetObjectPlainArgsBuilder.() -> Unit): GetObjectResult

Return

A collection of values returned by getObject.

Parameters

argument

Builder for com.pulumi.aws.s3.kotlin.inputs.GetObjectPlainArgs.

See also