Assets & archives
The Pulumi SDK provides two classes for working with files: Asset
and Archive
. Some Pulumi resource inputs accept either an Asset
or an Archive
as input, and Pulumi understands how to take the files referenced by the Asset
or Archive
and package them up for use by the resource. There are several different concrete implementations of these two concepts, based on the three ways the files might be provided, whether in memory, on disk, or in an archive. Similarly, files can be consumed by resources that expect a variety of packaging formats.
Assets
There are three types of Asset
objects:
FileAsset
: The contents of the asset are read from a file on disk.StringAsset
: The contents of the asset are read from a string in memory.RemoteAsset
: The contents of the asset are read from anhttp
,https
orfile
URI.
let fileAsset = new pulumi.asset.FileAsset("./file.txt");
let stringAsset = new pulumi.asset.StringAsset("Hello, world!");
let remoteAsset = new pulumi.asset.RemoteAsset("http://worldclockapi.com/api/json/est/now");
let fileAsset = new pulumi.asset.FileAsset("./file.txt");
let stringAsset = new pulumi.asset.StringAsset("Hello, world!");
let remoteAsset = new pulumi.asset.RemoteAsset("http://worldclockapi.com/api/json/est/now");
file_asset = pulumi.FileAsset("./file.txt")
string_asset = pulumi.StringAsset("Hello, world!")
remote_asset = pulumi.RemoteAsset("http://worldclockapi.com/api/json/est/now")
fileAsset := pulumi.NewFileAsset("./file.txt")
stringAsset := pulumi.NewStringAsset("Hello, world!")
remoteAsset := pulumi.NewRemoteAsset("http://worldclockapi.com/api/json/est/now")
using Pulumi;
var fileAsset = new FileAsset("./file.txt");
var stringAsset = new StringAsset("Hello, world!");
var remoteAsset = new RemoteAsset("http://worldclockapi.com/api/json/est/now");
final var fileAsset = new com.pulumi.asset.FileAsset("./file.txt");
final var stringAsset = new com.pulumi.asset.StringAsset("Hello, world!");
final var remoteAsset = new com.pulumi.asset.RemoteAsset("http://worldclockapi.com/api/json/est/now");
variables:
fileAsset:
fn::fileAsset: ./file.txt
stringAsset:
fn::stringAsset: Hello, world!
remoteAsset:
fn::remoteAsset: http://worldclockapi.com/api/json/est/now
Any of these assets can be passed to a resource accepting an Asset
as input.
let object = new aws.s3.BucketObject(`obj`, {
bucket: bucket.id,
key: key,
source: fileAsset,
});
let object = new aws.s3.BucketObject("obj", {
bucket: bucket.id,
key: key,
source: fileAsset,
});
obj = aws.s3.BucketObject("obj",
bucket=bucket.id,
key=key,
source=file_asset)
obj, err := s3.NewBucketObject(ctx, "obj", &s3.BucketObjectArgs{
Bucket: bucket.ID(),
Key: key,
Source: fileAsset,
})
var obj = new Aws.S3.BucketObject("obj", new Aws.S3.BucketObjectArgs
{
Bucket = bucket.Id,
Key = key,
Source = fileAsset,
});
var obj = new com.pulumi.aws.s3.BucketObject("obj",
com.pulumi.aws.s3.BucketObjectArgs.builder()
.bucket(bucket.getId())
.key(key)
.source(fileAsset)
.build());
resources:
obj:
type: aws:s3:BucketObject
properties:
bucket: ${bucket}
key: ${key}
source: ${fileAsset}
Archives
There are three types of Archive
objects:
FileArchive
: The contents of the archive are read from either a folder on disk or a file on disk in one of the supported formats:.tar
,.tgz
,.tar.gz
,.zip
or.jar
.RemoteArchive
: The contents of the asset are read from anhttp
,https
orfile
URI, which must produce an archive of one of the same supported types asFileArchive
.AssetArchive
: The contents of the archive are read from a map of eitherAsset
orArchive
objects, one file or folder respectively per entry in the map.
let fileArchive = new pulumi.asset.FileArchive("./file.zip");
let remoteArchive = new pulumi.asset.RemoteArchive("http://contoso.com/file.zip");
let assetArchive = new pulumi.asset.AssetArchive({
"file": new pulumi.asset.StringAsset("Hello, world!"),
"folder": new pulumi.asset.FileArchive("./folder"),
});
let fileArchive = new pulumi.asset.FileArchive("./file.zip");
let remoteArchive = new pulumi.asset.RemoteArchive("http://contoso.com/file.zip");
let assetArchive = new pulumi.asset.AssetArchive({
"file": new pulumi.asset.StringAsset("Hello, world!"),
"folder": new pulumi.asset.FileArchive("./folder"),
});
file_archive = pulumi.FileArchive("./file.zip")
remote_archive = pulumi.RemoteArchive("http://contoso.com/file.zip")
asset_archive = pulumi.AssetArchive({
"file": pulumi.StringAsset("Hello, world!"),
"folder": pulumi.FileArchive("./folder")
})
fileArchive := pulumi.NewFileArchive("./file.zip")
remoteArchive := pulumi.NewRemoteArchive("http://contoso.com/file.zip")
assetArchive := pulumi.NewAssetArchive(map[string]interface{}{
"file": pulumi.NewStringAsset("Hello, world!"),
"folder": pulumi.NewFileArchive("./folder"),
})
using Pulumi;
var fileArchive = new FileArchive("./file.zip");
var remoteArchive = new RemoteArchive("http://contoso.com/file.zip");
var assetArchive = new AssetArchive(new Dictionary<string, string>
{
{ "file", new StringAsset("Hello, world!") },
{ "folder", new FileArchive("./folder") }
});
var fileArchive = new com.pulumi.asset.FileArchive("./file.zip");
var remoteArchive = new com.pulumi.asset.RemoteArchive("http://contoso.com/file.zip");
var assetArchive = new com.pulumi.asset.AssetArchive(
Map.of(
"file", new com.pulumi.asset.StringAsset("Hello, world!"),
"folder", new com.pulumi.asset.FileArchive("./folder")));
variables:
fileArchive:
fn::fileArchive: ./file.zip
remoteArchive:
fn::remoteArchive: http://contoso.com/file.zip
assetArchive:
fn::assetArchive:
file:
fn::stringAsset: Hello, World!
folder:
fn::fileArchive: ./folder
Note that a folder may be passed to FileArchive
to construct an archive from the contents of that folder. Also, both assets (single files) and archives (folders containing files) can be combined as part of building up an AssetArchive
.
Any of these archives can be passed to a resource accepting an Archive
as input.
let fn = new aws.lambda.Function(`fn`, {
role: role.arn,
runtime: "python3.7",
handler: "hello.handler",
code: fileArchive,
});
let fn = new aws.lambda.Function(`fn`, {
role: role.arn,
runtime: "python3.7",
handler: "hello.handler",
code: fileArchive,
});
fn = lambda_.Function("fn",
role=role.arn,
runtime="python3.7",
handler="hello.handler",
code=file_archive)
fn, err := lambda.NewFunction(ctx, "fn", &lambda.FunctionArgs{
Bucket: role.ARN(),
Runtime: "python3.7",
Handler: "hello.handler",
Code: fileArchive,
})
var fn = new Aws.Lambda.Function("fn", new Aws.Lambda.FunctionArgs
{
Role = role.arn,
Runtime = "python3.7",
Handler = "hello.handler",
Code = fileArchive,
});
var fn = new com.pulumi.aws.lambda.Function("fn",
com.pulumi.aws.lambda.FunctionArgs.builder()
.role(role.arn())
.runtime("python3.7")
.handler("hello.handler")
.code(fileArchive)
.build());
resources:
fn:
type: aws:lambda:Function
properties:
role: ${role.arn}
runtime: python3.7
handler: hello.handler
code: ${fileArchive}
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.