Use cases
Staging then deploying a lambda function
This example assumes you deploy your code via a CloudFormation template like this:
Parameters:
BuildBucket:
Type: String
BuildKey:
Type: String
BuildHash:
Type: String
Resources:
Function:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket:
Ref: BuildBucket
S3Key:
Ref: BuildKey
FunctionVersion:
Type: AWS::Lambda::Version
Properties:
CodeSha256:
Ref: BuildHash
FunctionName:
Ref: Function
When you’re ready to stage your code:
Package it as a zip.
Attach the hash as metadata.
$ hash="$(openssl dgst -sha256 -binary dist.zip | openssl enc -base64)"
$ startifact MyLambdaProject 1.0.1 --stage dist.zip --metadata "hash=${hash:?}"
Now, to populate your CloudFormation template’s parameters:
Create a Startifact session. Since Lambda requires the function and its code to reside in the same region, you can restrict the session to your deployment region by passing it as
regions=["<region>"]
.get()
the artifact to deploy.Read the artifact’s
bucket
andkey
via itsdownloader
.Read the artifact’s hash from its metadata.
from startifact import Session
session = Session(regions=["us-east-1"])
artifact = session.get("MyLambdaProject", "1.0.1")
params.add("BuildBucket", artifact.downloader.bucket)
params.add("BuildKey", artifact.downloader.key)
params.add("BuildHash", artifact["hash"])