Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-cdk/aws-lambda

Package Overview
Dependencies
Maintainers
5
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-cdk/aws-lambda

The CDK Construct Library for AWS::Lambda

  • 1.101.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created

What is @aws-cdk/aws-lambda?

@aws-cdk/aws-lambda is an AWS Cloud Development Kit (CDK) module that allows you to define AWS Lambda functions and manage their configurations using code. It provides a high-level, object-oriented abstraction to define and deploy Lambda functions, making it easier to integrate with other AWS services and manage infrastructure as code.

What are @aws-cdk/aws-lambda's main functionalities?

Define a Lambda Function

This code defines a simple AWS Lambda function using the AWS CDK. The function uses Node.js 14.x runtime, specifies the handler, and points to the code directory.

const lambda = require('@aws-cdk/aws-lambda');
const cdk = require('@aws-cdk/core');

class MyStack extends cdk.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    new lambda.Function(this, 'MyFunction', {
      runtime: lambda.Runtime.NODEJS_14_X,
      handler: 'index.handler',
      code: lambda.Code.fromAsset('lambda'),
    });
  }
}

const app = new cdk.App();
new MyStack(app, 'MyStack');

Add Environment Variables

This code demonstrates how to add environment variables to an AWS Lambda function using the AWS CDK.

const lambda = require('@aws-cdk/aws-lambda');
const cdk = require('@aws-cdk/core');

class MyStack extends cdk.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    new lambda.Function(this, 'MyFunction', {
      runtime: lambda.Runtime.NODEJS_14_X,
      handler: 'index.handler',
      code: lambda.Code.fromAsset('lambda'),
      environment: {
        KEY: 'value',
      },
    });
  }
}

const app = new cdk.App();
new MyStack(app, 'MyStack');

Add Permissions to Lambda Function

This code shows how to add permissions to an AWS Lambda function using the AWS CDK. In this example, the Lambda function is granted permission to get objects from an S3 bucket.

const lambda = require('@aws-cdk/aws-lambda');
const cdk = require('@aws-cdk/core');
const iam = require('@aws-cdk/aws-iam');

class MyStack extends cdk.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    const myFunction = new lambda.Function(this, 'MyFunction', {
      runtime: lambda.Runtime.NODEJS_14_X,
      handler: 'index.handler',
      code: lambda.Code.fromAsset('lambda'),
    });

    myFunction.addToRolePolicy(new iam.PolicyStatement({
      actions: ['s3:GetObject'],
      resources: ['arn:aws:s3:::my-bucket/*'],
    }));
  }
}

const app = new cdk.App();
new MyStack(app, 'MyStack');

Other packages similar to @aws-cdk/aws-lambda

Keywords

FAQs

Package last updated on 28 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc