Pulumi 시작하기 - Asset과 Archive
Cloud

Pulumi 시작하기 - Asset과 Archive

일시불

Assets and Archives

Pulumi SDK는 파일을 핸들링하는데 Asset과 Archive 두개의 클래스를 사용한다. Pulumi SDK의 각 리소스 API들은 각각 Asset 또는 Archive를 요구하며, 그에 해당하는 객체를 인자로 입력하면 내부적으로 알아서 해석하도록 되어있다.

Assets

  • FileAsset : Asset의 컨텐츠를 디스크로부터 읽어온다.
  • StringAsset: Asset의 컨텐츠를 메모리로부터 읽어온다.
  • RemoteAsset : Asset의 컨텐츠를 file URI의 http, https로부터 읽어온다.

예시 :

file_asset = pulumi.FileAsset("./file.txt")
string_asset = pulumi.StringAsset("Hello, world!")
remote_asset = pulumi.RemoteAsset("http://worldclockapi.com/api/json/est/now")

s3.BucketObject 클래스는 source로 어떤 종류의 Asset이든 받을 수 있다.

obj = aws.s3.BucketObject("obj",
    bucket=bucket.id,
    key=key,
    source=fileAsset)

Archives

  • FileArchive: 컨텐츠를 압축파일 또는 폴더로부터 읽어온다. 압축파일은 다음 확장자를 지원한다: .tar, .tgz, .tar.gz, .zip or .jar.
  • RemoteArchive: FileArchive가 지원하는 타입의 Asset을 file URI의 http, https로부터 읽어온다.
  • AssetArchive: 컨텐츠를 Asset 또는 Archive의 map 에서 읽어온다. 각 파일 또는 폴더를 map의 엔트리에서 한개씩 가져온다. 파이썬의 경우는 dict 자료형의 엔트리로 저장된다.

예시:

file_archive = pulumi.FileArchive("./file.zip")
remote_archive = pulumi.RemoteArchive("http://contoso.com/file.zip")
asset_archive = pulumiAssetArchive({
    "file": pulumi.StringAsset("Hello, world!"),
    "folder": pulumi.FileArchive("./folder")
})

폴더 또한 FileArchive로 사용할 수 있다. 그리고 파일과 폴더를 한꺼번에 AssetArchive로 묶을 수도 있다.

fn = lambda_.Function("fn",
    role=role.arn,
    runtime="python3.7",
    handler="hello.handler",
    code=fileArchive)