How to use the @aws-cdk/aws-lambda.Code.asset 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-samples / amazon-cognito-example-for-external-idp / cdk / src / customResourceConstructs / cognitoDomainCustomResourceConstruct.ts View on Github external
constructor(scope: Construct, id: string, props: Omit,
              userPool: CfnUserPool | UserPool) {
    super(scope, id);

    this.node.addDependency(userPool);

    const userPoolArn = userPool instanceof CfnUserPool? userPool.attrArn : userPool.userPoolArn;
    const userPoolId = userPool instanceof CfnUserPool? userPool.ref : userPool.userPoolId;

    this.lambda = new lambda.SingletonFunction(this, "CognitoDomainCustomResource", {
      uuid: "090E4EFC-161E-4EBD-ADA2-72A7BE4A3120",
      code: Code.asset("./src/customResourceLambdas"),
      handler: "cognitoDomainCustomResourceHandler.handler",
      timeout: Duration.seconds(300),
      runtime: lambda.Runtime.NODEJS_10_X,

    });

    this.lambda.addToRolePolicy(
      // * is needed in case the user pool has changed, we may have more than one user pool this lambda needs to interact with
      new iam.PolicyStatement({actions: ["cognito-idp:*UserPoolDomain"], resources: [userPoolArn]})
    );
    this.lambda.addToRolePolicy(
      new iam.PolicyStatement({actions: ["cognito-idp:DescribeUserPoolDomain"], resources: ["*"]})
    );

    const resource = new cfn.CustomResource(this, "CognitoDomain", {
      provider: cfn.CustomResourceProvider.lambda(this.lambda),
github cloudcomponents / cdk-components / packages / cdk-pull-request-check / src / pull_request_check.ts View on Github external
}),
        );

        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', {
            projectName: `${repository.repositoryName}-pull-request`,
            source: Source.codeCommit({
                repository,
            }),
            environment: {
                buildImage,
                computeType,
            },
            buildSpec,
        });
github aws-samples / amazon-cognito-example-for-external-idp / cdk / src / customResourceConstructs / cognitoCustomResourceConstruct.ts View on Github external
constructor(scope: cdk.Construct, id: string, props: CognitoCustomResourceParams) {
    super(scope, id);

    this.lambda = new lambda.SingletonFunction(this, "Singleton", {
      uuid: "EBAA2A90-1BE2-44B4-ADF1-C267F9CD910A",
      code: Code.asset("./dist/customResourceLambdas"),
      handler: "cognitoCustomResourceHandler.handler",
      timeout: 300,
      runtime: lambda.Runtime.NodeJS810,

    });
    const resource = new cfn.CustomResource(this, "Resource", {
      provider: cfn.CustomResourceProvider.lambda(this.lambda),
      properties: {
        CognitoCustomResourceParams: props
      }
    });

    this.response.Domain = resource.getAtt("Domain").toString();
    this.response.AppClientId = resource.getAtt("AppClientId").toString();
    this.response.Region = resource.getAtt("Region").toString();
github seagull-js / seagull / packages / deploy / src / lib / cdk / stack.ts View on Github external
private addLambda() {
    const name = `${this.appName}-lambda`
    const conf = {
      code: Code.asset(`${this.folder}/.seagull/deploy`),
      description: 'universal route',
      functionName: `${name}-handler`,
      handler: 'dist/assets/backend/lambda.handler',
      memorySize: 3008,
      role: this.role,
      runtime: Runtime.NodeJS810,
      timeout: 300,
    }

    const lambdaFunction = new LambdaFunction(this, name, conf)
    this.defaultIntegration = new LambdaIntegration(lambdaFunction)
  }
github aws-samples / amazon-cognito-example-for-external-idp / cdk / src / customResourceConstructs / cognitoIdPCustomResourceConstruct.ts View on Github external
constructor(scope: Construct, id: string, props: Omit,
              userPool: CfnUserPool | UserPool) {
    super(scope, id);

    this.node.addDependency(userPool);

    const userPoolArn = userPool instanceof CfnUserPool? userPool.attrArn : userPool.userPoolArn;
    const userPoolId = userPool instanceof CfnUserPool? userPool.ref : userPool.userPoolId;

    this.lambda = new lambda.SingletonFunction(this, "CognitoIdPCustomResource", {
      uuid: "3C33B180-0D96-48BF-8A5E-6FD13B71511E",
      code: Code.asset("./src/customResourceLambdas"),
      handler: "cognitoIdPCustomResourceHandler.handler",
      timeout:  Duration.seconds(300),
      runtime: lambda.Runtime.NODEJS_10_X,

    });

    this.lambda.addToRolePolicy(new iam.PolicyStatement({
      actions: ["cognito-idp:*IdentityProvider*"],
      resources: [userPoolArn]
    }));

    const resource = new cfn.CustomResource(this, "CognitoIdP", {
      provider: cfn.CustomResourceProvider.lambda(this.lambda),
      properties: {
        Props: {...props, UserPoolId: userPoolId}
      }
github aws-samples / amazon-cognito-example-for-external-idp / cdk / src / customResourceConstructs / cognitoPreTokenGenerationResourceConstruct.ts View on Github external
this.node.addDependency(userPool);
    this.node.addDependency(preTokenLambda);

    const userPoolArn = userPool instanceof CfnUserPool? userPool.attrArn : userPool.userPoolArn;
    const userPoolId = userPool instanceof CfnUserPool? userPool.ref : userPool.userPoolId;

    preTokenLambda.addPermission("permission", {
      principal : new ServicePrincipal("cognito-idp.amazonaws.com"),
      action: "lambda:InvokeFunction",
      sourceArn: userPoolArn
    });

    this.lambda = new lambda.SingletonFunction(this, "CognitoPreTokenGenerationCustomResource", {
      uuid: "94418158-75C4-4A49-A10D-38F8096AEE52",
      code: Code.asset("./src/customResourceLambdas"),
      handler: "cognitoPreTokenGenerationCustomResourceHandler.handler",
      timeout: Duration.seconds(300),
      runtime: lambda.Runtime.NODEJS_10_X,

    });

    let customResourceLambdaPolicy = new iam.PolicyStatement({
      actions: ["cognito-idp:DescribeUserPool", "cognito-idp:UpdateUserPool"],
      resources: [userPoolArn]
    });

    this.lambda.addToRolePolicy(customResourceLambdaPolicy);

    const props: CognitoPreTokenGenerationParams = {
      PreTokenGenerationLambdaArn: preTokenLambda.functionArn,
      UserPoolId: userPoolId
github cloudcomponents / cdk-components / packages / cdk-codepipeline-slack / src / slack-notifier.ts View on Github external
SLACK_CHANNEL: slackChannel || '',
            SLACK_CHANNEL_ID: slackChannelId || '',
        };

        if (slackBotName) {
            this.environment.SLACK_BOT_NAME = slackBotName;
        }

        if (slackBotIcon) {
            this.environment.SLACK_BOT_ICON = slackBotIcon;
        }

        const notifier = new Function(scope, 'SlackNotifierFunction', {
            runtime: Runtime.NODEJS_10_X,
            handler: 'lib/notifier.handler',
            code: Code.asset(
                path.join(__dirname, '..', 'lambda', 'bundle.zip'),
            ),
            environment: this.environment,
        });
        notifier.addToRolePolicy(
            new PolicyStatement({
                resources: [pipeline.pipelineArn],
                actions: [
                    'codepipeline:GetPipelineState',
                    'codepipeline:GetPipelineExecution',
                ],
            }),
        );

        pipeline.onStateChange('SlackPipelineNotifierRule', {
            target: new LambdaFunction(notifier),
github cloudcomponents / cdk-components / packages / cdk-codepipeline-slack / src / slack-approval-action.ts View on Github external
const environment = {
            SLACK_BOT_TOKEN: this.props.slackBotToken,
            SLACK_SIGNING_SECRET: this.props.slackSigningSecret,
            SLACK_CHANNEL: this.props.slackChannel as string,
            SLACK_CHANNEL_ID: this.props.slackChannelId as string,
            SLACK_BOT_NAME: this.props.slackBotName || 'buildbot',
            SLACK_BOT_ICON: this.props.slackBotIcon || ':robot_face:',
        };

        const approvalRequester = new Function(
            scope,
            'SlackApprovalRequesterFunction',
            {
                runtime: Runtime.NODEJS_10_X,
                handler: 'lib/approval-requester.handler',
                code: Code.asset(
                    path.join(__dirname, '..', 'lambda', 'bundle.zip'),
                ),
                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',
github seagull-js / seagull / packages / deploy-aws / src / seagull_stack.ts View on Github external
addLambda(name: string, folder: string, role: IAM.Role, env: Keymap) {
    const lambdaName = `${this.id}-${name}`
    const conf = {
      code: Code.asset(`${folder}/.seagull/deploy`),
      description: 'universal route',
      environment: env,
      functionName: `${lambdaName}-handler`,
      handler: 'dist/assets/backend/lambda.handler',
      memorySize: 1536,
      role,
      runtime: Runtime.NodeJS810,
      timeout: 300,
    }
    return new Lambda(this, lambdaName, conf)
  }