How to use the @aws-cdk/aws-lambda.SingletonFunction function in @aws-cdk/aws-lambda

To help you get started, we’ve selected a few @aws-cdk/aws-lambda 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 aws / aws-cdk / packages / @aws-cdk / aws-s3-deployment / lib / bucket-deployment.ts View on Github external
constructor(scope: cdk.Construct, id: string, props: BucketDeploymentProps) {
    super(scope, id);

    if (props.distributionPaths && !props.distribution) {
      throw new Error("Distribution must be specified if distribution paths are specified");
    }

    const sourceHash = calcSourceHash(handlerSourceDirectory);
    // tslint:disable-next-line: no-console
    console.error({sourceHash});

    const handler = new lambda.SingletonFunction(this, 'CustomResourceHandler', {
      uuid: this.renderSingletonUuid(props.memoryLimit),
      code: lambda.Code.fromAsset(handlerCodeBundle, { sourceHash }),
      runtime: lambda.Runtime.PYTHON_3_6,
      handler: 'index.handler',
      lambdaPurpose: 'Custom::CDKBucketDeployment',
      timeout: cdk.Duration.minutes(15),
      role: props.role,
      memorySize: props.memoryLimit
    });

    const sources: SourceConfig[] = props.sources.map((source: ISource) => source.bind(this));
    sources.forEach(source => source.bucket.grantRead(handler));

    props.destinationBucket.grantReadWrite(handler);
    if (props.distribution) {
      handler.addToRolePolicy(new iam.PolicyStatement({
github aws / aws-cdk / packages / @aws-cdk / aws-stepfunctions-tasks / lib / evaluate-expression.ts View on Github external
function createEvalFn(runtime: lambda.Runtime, scope: cdk.Construct) {
  const code = lambda.Code.asset(path.join(__dirname, `eval-${runtime.name}-handler`));
  const lambdaPurpose = 'Eval';

  switch (runtime) {
    case lambda.Runtime.NODEJS_10_X:
      return new lambda.SingletonFunction(scope, 'EvalFunction', {
        runtime,
        handler: 'index.handler',
        uuid: 'a0d2ce44-871b-4e74-87a1-f5e63d7c3bdc',
        lambdaPurpose,
        code,
      });
    // TODO: implement other runtimes
    default:
      throw new Error(`The runtime ${runtime.name} is currently not supported.`);
  }
}
github cloudcomponents / cdk-components / packages / cdk-stripe-webhook / src / stripe-webhook.ts View on Github external
public constructor(
        scope: Construct,
        id: string,
        props: StripeWebhookProps,
    ) {
        super(scope, id);

        const handler = new SingletonFunction(this, 'CustomResourceHandler', {
            uuid: 'e9db3870-d793-4cd2-96a9-efe2e318ebbc',
            runtime: Runtime.NODEJS_10_X,
            code: Code.fromAsset(
                path.join(__dirname, '..', 'lambda', 'bundle.zip'),
            ),
            handler: 'lib/stripe-webhook.handler',
            lambdaPurpose: 'Custom::StripeWebhook',
            timeout: Duration.minutes(15),
        });

        new CustomResource(this, 'CustomResource', {
            provider: CustomResourceProvider.lambda(handler),
            resourceType: 'Custom::StripeWebhook',
            properties: {
                ...props,
            },
github cloudcomponents / cdk-components / packages / cdk-github-webhook / src / github-webhook.ts View on Github external
public constructor(
        parent: Construct,
        id: string,
        props: GithubWebhookProps,
    ) {
        super(parent, id);

        const handler = new SingletonFunction(this, 'CustomResourceHandler', {
            uuid: '83CBF3EB-7B62-44F2-8C67-8441E4C1232E',
            runtime: Runtime.NODEJS_10_X,
            code: Code.fromAsset(
                path.join(__dirname, '..', 'lambda', 'bundle.zip'),
            ),
            handler: 'lib/github-webhook.handler',
            lambdaPurpose: 'Custom::GithubWebhook',
            timeout: Duration.minutes(15),
        });

        const {
            githubApiToken,
            githubRepoUrl,
            payloadUrl,
            events,
            logLevel,
github cloudcomponents / cdk-components / packages / cdk-contentful-webhook / src / contentful-webhook.ts View on Github external
public constructor(
        scope: Construct,
        id: string,
        props: ContentfulWebhookProps,
    ) {
        super(scope, id);

        const handler = new SingletonFunction(this, 'CustomResourceHandler', {
            uuid: '91f2075f-b950-4743-a66b-ee0f6febf50d',
            runtime: Runtime.NODEJS_10_X,
            code: Code.fromAsset(
                path.join(__dirname, '..', 'lambda', 'bundle.zip'),
            ),
            handler: 'lib/contentful-webhook.handler',
            lambdaPurpose: 'Custom::ContentfulWebhook',
            timeout: Duration.minutes(15),
        });

        new CustomResource(this, 'CustomResource', {
            provider: CustomResourceProvider.lambda(handler),
            resourceType: 'Custom::ContentfulWebhook',
            properties: {
                ...props,
            },