Assets and 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,httpsoffileURI.
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");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,
});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,.zipor.jar.RemoteArchive: The contents of the asset are read from anhttp,httpsoffileURI, 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 eitherAssetorArchiveobjects, 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"),
});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,
});