How to use the @aws-cdk/aws-lambda.Code.fromAsset 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 cloudcomponents / cdk-components / packages / cdk-codepipeline-check-parameter-action / src / codepipeline-check-parameter-action.ts View on Github external
protected bound(
        scope: Construct,
        _stage: IStage,
        options: ActionBindOptions,
    ): ActionConfig {
        const { parameterName, regExp, logParameter = false } = this.props;

        const checkParameterFunction = new Function(
            scope,
            'CheckParamterFunction',
            {
                runtime: Runtime.PYTHON_3_7,
                code: Code.fromAsset(`${LAMBDA_PATH}/check-parameter`),
                handler: 'check_parameter.lambda_handler',
            },
        );

        // allow pipeline to list functions
        options.role.addToPolicy(
            new PolicyStatement({
                actions: ['lambda:ListFunctions'],
                resources: ['*'],
            }),
        );

        // allow pipeline to invoke this lambda functionn
        options.role.addToPolicy(
            new PolicyStatement({
                actions: ['lambda:InvokeFunction'],
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,
        } = props;

        new CustomResource(this, 'CustomResource', {
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,
            },
        });
    }
}
github cloudcomponents / cdk-components / packages / cdk-pull-request-check / src / pull_request_check.ts View on Github external
new PolicyStatement({
                resources: ['*'],
                actions: [
                    'codebuild:*',
                    'codecommit:*',
                    'logs:CreateLogGroup',
                    'logs:CreateLogStream',
                    'logs:PutLogEvents',
                    'logs:GetLogEvents',
                ],
            }),
        );

        const pullRequestFunction = new Function(this, 'PullRequestFunction', {
            runtime: Runtime.PYTHON_3_7,
            code: Code.fromAsset(`${lambdaPath}/pull-request`),
            handler: 'pull_request.lambda_handler',
            role: lambdaRole,
        });

        const codeBuildResultFunction = new Function(
            this,
            'CodeBuildResultFunction',
            {
                runtime: Runtime.PYTHON_3_7,
                code: Code.asset(`${lambdaPath}/code-build-result`),
                handler: 'code_build_result.lambda_handler',
                role: lambdaRole,
            },
        );

        const pullRequestProject = new Project(this, 'PullRequestProject', {
github cloudcomponents / cdk-components / packages / cdk-codepipeline-slack / src / slack-approval-action.ts View on Github external
),
                environment,
            },
        );

        const topic = new Topic(scope, 'SlackApprovalTopic');
        topic.grantPublish(options.role);
        topic.addSubscription(new LambdaSubscription(approvalRequester));

        const approvalHandler = new Function(
            scope,
            'SlackApprovalHandlerFunction',
            {
                runtime: Runtime.NODEJS_10_X,
                handler: 'lib/approval-handler.handler',
                code: Code.fromAsset(
                    path.join(__dirname, '..', 'lambda', 'bundle.zip'),
                ),
                environment,
            },
        );

        const api = new RestApi(scope, 'SlackApprovalApi');
        api.root.addProxy({
            defaultIntegration: new LambdaIntegration(approvalHandler),
        });

        approvalHandler.addToRolePolicy(
            new PolicyStatement({
                actions: ['codepipeline:PutApprovalResult'],
                resources: [
                    `${stage.pipeline.pipelineArn}/${stage.stageName}/${this.props.actionName}`,
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,
            },
        });
    }
}