Skip to content

Instantly share code, notes, and snippets.

@cnunciato
Last active April 19, 2024 23:03
Show Gist options
  • Save cnunciato/2461f87e59b3b50c14cbefc33b91738e to your computer and use it in GitHub Desktop.
Save cnunciato/2461f87e59b3b50c14cbefc33b91738e to your computer and use it in GitHub Desktop.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as textToImage from "text-to-image";
// Make a bucket, which computes a randomly generated name.
const bucket = new aws.s3.Bucket("my-bucket");
// When the bucket ID is available, render a buffer of PNG bytes containing it.
const image = bucket.id.apply(bucketID => {
const dataUri = textToImage.generateSync(`Rendered with 💜 to s3://${bucketID} with Pulumi.`, {
verticalAlign: "center",
fontSize: 14,
textColor: "#ffffff",
bgColor: "#66489c",
});
return Buffer.from(dataUri.split(",")[1], "base64");
});
// Write the image to S3.
const bucketObject = new aws.s3.BucketObject("my-image.png", {
bucket: bucket.id,
contentBase64: image.apply(i => i.toString("base64")), // Convert the buffer to base 64.
contentType: "text/png",
});
export const bucketID = bucket.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment