How to use the @pulumi/aws.lambda function in @pulumi/aws

To help you get started, we’ve selected a few @pulumi/aws 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 mapbox / asset-tracking / src / index.js View on Github external
.promise();
      console.log(fhStatus);

      console.log("Writing to IoT");
      const ioTParams = {
        topic: iotFrontEnd,
        payload: JSON.stringify(params.Item),
        qos: 0
      };
      const ioTStatus = await iot.publish(ioTParams).promise();
      console.log(ioTStatus);
    }
  }
});

const kinesisLambdaEventMapping = new aws.lambda.EventSourceMapping(
  "map2Kinesis",
  {
    //This defines how many records to pick up per Lambda invocation.
    //You will need to align this against ingestion volume and processing time.
    batchSize: 25,
    enabled: true,
    eventSourceArn: ingestStream.arn,
    functionName: kinesisLambda.name,
    startingPosition: "LATEST"
  }
);


//* This section writes all the necessary files for testing and validation
const harnessCert = new aws.iot.Certificate("harnessCert", {
  active: true
github communitybridge / easycla / infra / index.ts View on Github external
const dynamoDBEventsEventLambdaName = "cla-backend-" + stage + "-dynamo-events-events-lambda";
const dynamoDBEventsEventLambdaArn = "arn:aws:lambda:" + aws.getRegion().name + ":" + accountID + ":function:" + dynamoDBEventsEventLambdaName;
eventsTable.onEvent("eventStreamEvents",
  aws.lambda.Function.get(dynamoDBEventsEventLambdaName, dynamoDBEventsEventLambdaArn),
  { startingPosition: "LATEST" });

const dynamoDBProjectsCLAGroupsEventLambdaName = "cla-backend-" + stage + "-dynamo-projects-cla-groups-events-lambda";
const dynamoDBProjectsCLAGroupsEventLambdaArn = "arn:aws:lambda:" + aws.getRegion().name + ":" + accountID + ":function:" + dynamoDBProjectsCLAGroupsEventLambdaName;
projectsClaGroupsTable.onEvent("projectsCLAGroupsStreamEvents",
  aws.lambda.Function.get(dynamoDBProjectsCLAGroupsEventLambdaName, dynamoDBProjectsCLAGroupsEventLambdaArn),
  { startingPosition: "LATEST" });

const dynamoDBRepositoriesEventLambdaName = "cla-backend-" + stage + "-dynamo-repositories-events-lambda";
const dynamoDBRepositoriesEventLambdaArn = "arn:aws:lambda:" + aws.getRegion().name + ":" + accountID + ":function:" + dynamoDBRepositoriesEventLambdaName;
repositoriesTable.onEvent("repositoriesStreamEvents",
  aws.lambda.Function.get(dynamoDBRepositoriesEventLambdaName, dynamoDBRepositoriesEventLambdaArn),
  { startingPosition: "LATEST" });

// Export the name of the bucket
export const logoBucketARN = logoBucket.arn;
export const logoBucketName = logoBucket.bucket;
export const logoBucketPolicyOutput = logoBucketPolicy.policy;
export const signatureFilesBucketARN = signatureFilesBucket.arn;
export const signatureFilesBucketName = signatureFilesBucket.bucket;
export const projectsTableName = projectsTable.name;
export const projectsTableARN = projectsTable.arn;
export const companiesTableName = companiesTable.name;
export const companiesTableARN = companiesTable.arn;
export const usersTableName = usersTable.name;
export const usersTableARN = usersTable.arn;
export const signaturesTableName = signaturesTable.name;
export const signaturesTableARN = signaturesTable.arn;
github fanout / apollo-serverless-demo / src / FanoutGraphqlAwsApp.ts View on Github external
const FanoutGraphqlAwsApp = (
  name: string,
  options: IFanoutGraphqlAwsAppOptions,
) => {
  const webSocketOverHttpStorage = {
    connections: new cloud.Table(`${name}-connections`),
    subscriptions: new cloud.Table(`${name}-subscriptions`),
  }

  // AWS Resources for serving GraphQL API over HTTP
  const httpLambdaFunction = new aws.lambda.CallbackFunction(`${name}-fn-graphql`, {
    callback: FanoutGraphqlAppLambdaCallback({
      grip: options.grip,
      pubsub: options.pubsub,
      tables: {
        notes: new cloud.Table(`${name}-notes`),
        ...webSocketOverHttpStorage,
      },
    }),
    timeout: 30,
  });
  const routes: awsx.apigateway.Route[] = [
    {
      eventHandler: httpLambdaFunction,
      method: "GET",
      path: "/",
    },
github pulumi / pulumi-awsx / nodejs / examples / api / index.ts View on Github external
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
import * as pulumi from "@pulumi/pulumi";

// Create role for our lambda
const role = new aws.iam.Role("mylambda-role", {
    assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ "Service": ["lambda.amazonaws.com", "apigateway.amazonaws.com"] }),
});

// Create the lambda whose code lives in the ./afunction directory
const lambda = new aws.lambda.Function("myfunction", {
    code: new pulumi.asset.FileArchive("./afunction"),
    role: role.arn,
    handler: "index.handler",
    runtime: aws.lambda.NodeJS8d10Runtime,
});

// Define the Authorizers up here so we can use it for two routes. Note - if you are sharing an
// authorizer you will want to set the authorizerResultTtlInSeconds to 0 seconds or else it will
// cause problems for you.
const lambdaAuthorizer: awsx.apigateway.LambdaAuthorizer = {
    authorizerName: "prettyAuthorizer",
    parameterName: "auth",
    parameterLocation: "query",
    authType: "custom",
    type: "request",
    handler: async (event: awsx.apigateway.AuthorizerEvent) => {
        return awsx.apigateway.authorizerResponse("user", "Allow", event.methodArn);
    },
    identitySource: ["method.request.querystring.auth"],
    authorizerResultTtlInSeconds: 0,
github pulumi / actions-pulumify / infra / bucketDirectory.ts View on Github external
assumeRolePolicy: {
                Version: "2012-10-17",
                Statement: [{
                    Action: "sts:AssumeRole",
                    Principal: {
                        Service: "lambda.amazonaws.com"
                    },
                    Effect: "Allow",
                    Sid: "",
                }],
            },
            tags: {
              "Owner": "Pulumify",
            }
        }, { parent });
        const syncFunc = new aws.lambda.Function(`${name}-copyfunc`, {
            timeout: 60*5,
            memorySize: 1024,
            runtime: "python3.7",
            code: new pulumi.asset.FileArchive("./lambda/bin"),
            handler: "index.handler",
            role: syncFuncRole.arn,
            tags: {
              "Owner": "Pulumify"
            }
        }, { parent });

        // Allow Lambda to read/write from the S3 bucket.
        const bucketArn = pulumi.interpolate`arn:aws:s3:::${bucket}`;
        const syncFuncPolicy = new aws.iam.Policy(`${name}-copyfunc-policy`, {
            path: "/",
            policy: {
github communitybridge / easycla / infra / index.ts View on Github external
},
      ],
      pointInTimeRecovery: {
        enabled: pointInTimeRecoveryEnabled,
      },
      tags: defaultTags,
    },
    importResources ? { import: 'cla-' + stage + '-projects-cla-groups' } : {},
  );
}

// DynamoDB trigger events handler functions
const dynamoDBSignaturesEventLambdaName = "cla-backend-" + stage + "-dynamo-signatures-events-lambda";
const dynamoDBSignaturesEventLambdaArn = "arn:aws:lambda:" + aws.getRegion().name + ":" + accountID + ":function:" + dynamoDBSignaturesEventLambdaName;
signaturesTable.onEvent("signatureStreamEvents",
  aws.lambda.Function.get(dynamoDBSignaturesEventLambdaName, dynamoDBSignaturesEventLambdaArn),
  { startingPosition: "LATEST" });

const dynamoDBEventsEventLambdaName = "cla-backend-" + stage + "-dynamo-events-events-lambda";
const dynamoDBEventsEventLambdaArn = "arn:aws:lambda:" + aws.getRegion().name + ":" + accountID + ":function:" + dynamoDBEventsEventLambdaName;
eventsTable.onEvent("eventStreamEvents",
  aws.lambda.Function.get(dynamoDBEventsEventLambdaName, dynamoDBEventsEventLambdaArn),
  { startingPosition: "LATEST" });

const dynamoDBProjectsCLAGroupsEventLambdaName = "cla-backend-" + stage + "-dynamo-projects-cla-groups-events-lambda";
const dynamoDBProjectsCLAGroupsEventLambdaArn = "arn:aws:lambda:" + aws.getRegion().name + ":" + accountID + ":function:" + dynamoDBProjectsCLAGroupsEventLambdaName;
projectsClaGroupsTable.onEvent("projectsCLAGroupsStreamEvents",
  aws.lambda.Function.get(dynamoDBProjectsCLAGroupsEventLambdaName, dynamoDBProjectsCLAGroupsEventLambdaArn),
  { startingPosition: "LATEST" });

const dynamoDBRepositoriesEventLambdaName = "cla-backend-" + stage + "-dynamo-repositories-events-lambda";
const dynamoDBRepositoriesEventLambdaArn = "arn:aws:lambda:" + aws.getRegion().name + ":" + accountID + ":function:" + dynamoDBRepositoriesEventLambdaName;
github pulumi / pulumi-awsx / nodejs / examples / ec2 / update2 / ec2.ts View on Github external
console.log(buffer.toString());
                await cache.set("page", buffer.toString());

                return {
                    statusCode: 200,
                    headers: { "X-Powered-By": "nginx" },
                    body: buffer.toString(),
                };
            } catch (err) {
                return handleError(err);
            }
        },
    }, {
        path: "/run",
        method: "GET",
        eventHandler: new aws.lambda.CallbackFunction("runRoute", {
            policies: [...awsx.ecs.TaskDefinition.defaultTaskRolePolicyARNs()],
            callback: async (req) => {
                try {
                    const result = await helloTask.run({ cluster: cluster1 });
                    return {
                        statusCode: 200,
                        body: JSON.stringify({ success: true, tasks: result.tasks }),
                    };
                } catch (err) {
                    return handleError(err);
                }
            },
        }),
    }, {
        path: "/custom",
        method: "GET",
github pulumi / pulumi-cloud / aws / logCollector.ts View on Github external
try {
                    const zlib = await import("zlib");
                    const payload = new Buffer(ev.awslogs.data, "base64");
                    const result = zlib.gunzipSync(payload);
                    console.log(result.toString("utf8"));
                    cb(null, {});
                } catch (err) {
                    cb(err);
                }
            },
            { parent: this },
        );
        this.lambda = collector.lambda;

        const region = aws.config.requireRegion();
        const permission = new aws.lambda.Permission(name, {
            action: "lambda:invokeFunction",
            function: this.lambda,
            principal: "logs." + region + ".amazonaws.com",
        }, { parent: this });
    }
}
github pulumi / pulumi-aws-serverless / nodejs / aws-serverless / examples / api / index.ts View on Github external
"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 serverless.apigateway.API("myapi", {
    routes: [
        { method: "GET", path: "/a", handler: async (event) => {
            return {
                statusCode: 200,
                body: "<h1>Hello world!</h1>",
            };
        }},
        { method: "GET", path: "/b", handler: lambda },
    ],
});

export const url = api.url;
github pulumi / pulumi-aws / examples / api / index.ts View on Github external
"Principal": {
                "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) =&gt; {
            return {
                statusCode: 200,
                body: "<h1>Hello world!</h1>",
            };
        },