How to use the @pulumi/pulumi.asset function in @pulumi/pulumi

To help you get started, we’ve selected a few @pulumi/pulumi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulumi / pulumi-aws / overlays / nodejs / serverless / function.ts View on Github external
const finalSerialize = (o: any) => {
            return serialize(o) && o !== this;
        }

        let closure = pulumi.runtime.serializeFunctionAsync(func, finalSerialize);
        if (!closure) {
            throw new Error("Failed to serialize function closure");
        }

        // console.log("Making function: " + name);
        this.lambda = new lambda.Function(name, {
            code: new pulumi.asset.AssetArchive({
                // TODO[pulumi/pulumi-aws#35] We may want to allow users to control what gets uploaded. Currently, we
                //     upload the entire folder as there may be dependencies on any files here.
                ".": new pulumi.asset.FileArchive("."),
                "__index.js": new pulumi.asset.StringAsset(closure),
            }),
            handler: "__index.handler",
            runtime: lambda.NodeJS6d10Runtime,
            role: this.role.arn,
            timeout: options.timeout === undefined ? 180 : options.timeout,
            memorySize: options.memorySize,
            deadLetterConfig: options.deadLetterConfig,
            vpcConfig: options.vpcConfig,
        }, { parent: this });
    }
}
github pulumi / examples / aws-js-s3-folder / index.js View on Github external
// Create a bucket and expose a website index document
let siteBucket = new aws.s3.Bucket("s3-website-bucket", {
    website: {
        indexDocument: "index.html",
    },
});

let siteDir = "www"; // directory for content files

// For each file in the directory, create an S3 object stored in `siteBucket`
for (let item of require("fs").readdirSync(siteDir)) {
    let filePath = require("path").join(siteDir, item);
    let object = new aws.s3.BucketObject(item, {
        bucket: siteBucket,                               // reference the s3.Bucket object
        source: new pulumi.asset.FileAsset(filePath),     // use FileAsset to point to a file
        contentType: mime.getType(filePath) || undefined, // set the MIME type of the file
    });
}

// Create an S3 Bucket Policy to allow public read of all objects in bucket
function publicReadPolicyForBucket(bucketName) {
    return {
        Version: "2012-10-17",
        Statement: [{
            Effect: "Allow",
            Principal: "*",
            Action: [
                "s3:GetObject"
            ],
            Resource: [
                `arn:aws:s3:::${bucketName}/*` // policy refers to bucket name explicitly
github pulumi / examples / aws-js-s3-folder-component / s3folder.js View on Github external
constructor(bucketName, path, opts) {
        super("pulumi:examples:S3Folder", bucketName, {}, opts); // Register this component with name pulumi:examples:S3Folder

        // Create a bucket and expose a website index document
        let siteBucket = new aws.s3.Bucket(bucketName, {
            website: {
                indexDocument: "index.html",
            },
        }, { parent: this }); // specify resource parent

        // For each file in the directory, create an S3 object stored in `siteBucket`
        for (let item of require("fs").readdirSync(path)) {
            let filePath = require("path").join(path, item);
            let object = new aws.s3.BucketObject(item, {
                bucket: siteBucket,                               // reference the s3.Bucket object
                source: new pulumi.asset.FileAsset(filePath),     // use FileAsset to point to a file
                contentType: mime.getType(filePath) || undefined, // set the MIME type of the file
            }, { parent: this }); // specify resource parent
        }

        // Set the access policy for the bucket so all objects are readable
        let bucketPolicy = new aws.s3.BucketPolicy("bucketPolicy", {
            bucket: siteBucket.bucket,
            policy: siteBucket.bucket.apply(this.publicReadPolicyForBucket),
        }, { parent: this }); // specify resource parent

        this.bucketName = siteBucket.bucket;
        this.websiteUrl = siteBucket.websiteEndpoint;

        // Register output properties for this component
        this.registerOutputs({
            bucketName: this.bucketName,
github pulumi / examples / azure-ts-appservice / index.ts View on Github external
size: "B1",
    },
});

const storageContainer = new azure.storage.Container(`${prefix}-c`, {
    storageAccountName: storageAccount.name,
    containerAccessType: "private",
});

const blob = new azure.storage.ZipBlob(`${prefix}-b`, {
    resourceGroupName: resourceGroup.name,
    storageAccountName: storageAccount.name,
    storageContainerName: storageContainer.name,
    type: "block",

    content: new pulumi.asset.FileArchive("wwwroot"),
});

const codeBlobUrl = azure.storage.signedBlobReadUrl(blob, storageAccount);

const appInsights = new azure.appinsights.Insights(`${prefix}-ai`, {
    ...resourceGroupArgs,

    applicationType: "Web",
});

const username = "pulumi";

// Get the password to use for SQL from config.
const config = new pulumi.Config();
const pwd = config.require("sqlPassword");
github pulumi / examples / azure-ts-functions-raw / index.ts View on Github external
// Azure Functions on Premium Plan
const premiumPlan = new azure.appservice.Plan("premium-asp", {
    resourceGroupName: resourceGroup.name,
    kind: "elastic",
    sku: {
        tier: "ElasticPremium",
        size: "EP1",
    },
    maximumElasticWorkerCount: 20,
});

const premiumApp = new azure.appservice.ArchiveFunctionApp("http-premium", {
    resourceGroup,
    plan: premiumPlan,
    archive: new pulumi.asset.FileArchive("./dotnet/bin/Debug/netcoreapp2.1/publish"),
    appSettings: {
        "runtime": "dotnet",
    },
});


export const dotnetEndpoint = dotnetApp.endpoint.apply(ep => `${ep}HelloDotnet?name=Pulumi`);
export const nodeEndpoint = nodeApp.endpoint.apply(ep => `${ep}HelloNode?name=Pulumi`);
export const powershellEndpoint = powershellApp.endpoint.apply(ep => `${ep}HelloPS?name=Pulumi`);
export const javaEndpoint = javaApp.endpoint.apply(ep => `${ep}HelloJava?name=Pulumi`);
export const pythonEndpoint = pythonApp.endpoint.apply(ep => `${ep}HelloPython?name=Pulumi`);
export const premiumEndpoint = premiumApp.endpoint.apply(ep => `${ep}HelloDotnet?name=PulumiOnPremium`);
github pulumi / examples / azure-ts-functions-raw / index.ts View on Github external
// Copyright 2016-2019, Pulumi Corporation.  All rights reserved.

import * as azure from "@pulumi/azure";
import * as pulumi from "@pulumi/pulumi";

// Create a resource group for Windows App Service Plan
const resourceGroup = new azure.core.ResourceGroup("windowsrg");

const dotnetApp = new azure.appservice.ArchiveFunctionApp("http-dotnet", {
    resourceGroup,
    archive: new pulumi.asset.FileArchive("./dotnet/bin/Debug/netcoreapp2.1/publish"),
    appSettings: {
        "runtime": "dotnet",
    },
});

const nodeApp = new azure.appservice.ArchiveFunctionApp("http-node", {
    resourceGroup,
    archive: new pulumi.asset.FileArchive("./javascript"),
});

const powershellApp = new azure.appservice.ArchiveFunctionApp("http-powershell", {
    resourceGroup,
    archive: new pulumi.asset.FileArchive("./powershell"),
    appSettings: {
        "runtime": "powershell",
    },
github pulumi / pulumi-aws / sdk / nodejs / lambda / zMixins.ts View on Github external
async function computeCodePaths(
        closure: Promise,
        serializedFileNameNoExtension: string,
        codePathOptions: pulumi.runtime.CodePathOptions | undefined): Promise {

    const serializedFunction = await closure;

    // Construct the set of paths to include in the archive for upload.
    let codePaths: pulumi.asset.AssetMap = {
        // Always include the serialized function.
        [serializedFileNameNoExtension + ".js"]: new pulumi.asset.StringAsset(serializedFunction.text),
    };

    // AWS Lambda always provides `aws-sdk`, so skip this.  Do this before processing user-provided
    // extraIncludePackages so that users can force aws-sdk to be included (if they need a specific
    // version).
    codePathOptions = codePathOptions || {};
    codePathOptions.extraExcludePackages = codePathOptions.extraExcludePackages || [];
    codePathOptions.extraExcludePackages.push("aws-sdk");

    const modulePaths = await pulumi.runtime.computeCodePaths(codePathOptions);

    for (const [path, asset] of modulePaths) {
        codePaths[path] = asset;
    }

    return codePaths;
github pulumi / pulumi-aws / examples / api / index.ts View on Github external
"Service": "lambda.amazonaws.com",
            },
            "Effect": "Allow",
            "Sid": "",
        },
    ],
};
const role = new aws.iam.Role("mylambda-role", {
    assumeRolePolicy: JSON.stringify(policy),
});
const fullAccess = new aws.iam.RolePolicyAttachment("mylambda-access", {
    role: role,
    policyArn: aws.iam.AWSLambdaFullAccess,
});
const lambda = new aws.lambda.Function("myfunction", {
    code: new pulumi.asset.FileArchive("./afunction"),
    role: role.arn,
    handler: "index.handler",
    runtime: aws.lambda.NodeJS8d10Runtime,
});

const api = new aws.apigateway.x.API("myapi", {
    routes: [{
        path: "/a",
        method: "GET",
        eventHandler: async (event) => {
            return {
                statusCode: 200,
                body: "<h1>Hello world!</h1>",
            };
        },
    }, {
github pulumi / infrastructure-as-code-workshop / labs / aws / typescript / lab-01 / code / 04-updating-your-infrastructure / step1.ts View on Github external
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as path from "path";

const myBucket = new aws.s3.Bucket("my-bucket");

const myObject = new aws.s3.BucketObject("index.html", {
    bucket: myBucket,
    source: new pulumi.asset.FileAsset(path.join("site", "index.html")),
});

export const bucketName = myBucket.bucket;
github pulumi / pulumi-google-native / examples / functions-ts / index.ts View on Github external
upper: false,
    number: false,
    special: false,
    length: 8,
});

const bucket = new google.storage.v1.Bucket("bucket", {
    project,
    name: pulumi.interpolate`bucket-${randomString.result}`,
});

const bucketObject = new google.storage.v1.BucketObject("bucketObject", {
    name: "zip",
    bucket: bucket.name,
    source: new pulumi.asset.AssetArchive({
        ".": new pulumi.asset.FileArchive("./pythonfunc"),
    }),
});

const functionName = pulumi.interpolate`func-${randomString.result}`;
const func = new google.cloudfunctions.v1.Function("function-py", {
    project,
    location: region,
    name: pulumi.interpolate`projects/${project}/locations/${region}/functions/${functionName}`,
    sourceArchiveUrl: pulumi.interpolate`gs://${bucket.name}/${bucketObject.name}`,
    httpsTrigger: {},
    entryPoint: "handler",
    timeout: "60s",
    availableMemoryMb: 128,
    runtime: "python37",
    ingressSettings: "ALLOW_ALL",
});