Show / Hide Table of Contents

Namespace Pulumi.Aws.Lambda

Classes

Alias

Creates a Lambda function alias. Creates an alias that points to the specified Lambda function version.

For information about Lambda and how to use it, see What is AWS Lambda? For information about function aliases, see CreateAlias and AliasRoutingConfiguration in the API docs.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var testAlias = new Aws.Lambda.Alias("testAlias", new Aws.Lambda.AliasArgs
    {
        Description = "a sample description",
        FunctionName = aws_lambda_function.Lambda_function_test.Arn,
        FunctionVersion = "1",
        RoutingConfig = new Aws.Lambda.Inputs.AliasRoutingConfigArgs
        {
            AdditionalVersionWeights = 
            {
                { "2", 0.5 },
            },
        },
    });
}

}

AliasArgs

AliasState

EventSourceMapping

Provides a Lambda event source mapping. This allows Lambda functions to get events from Kinesis, DynamoDB and SQS.

For information about Lambda and how to use it, see What is AWS Lambda?. For information about event source mappings, see CreateEventSourceMapping in the API docs.

Example Usage

DynamoDB

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var example = new Aws.Lambda.EventSourceMapping("example", new Aws.Lambda.EventSourceMappingArgs
    {
        EventSourceArn = aws_dynamodb_table.Example.Stream_arn,
        FunctionName = aws_lambda_function.Example.Arn,
        StartingPosition = "LATEST",
    });
}

}

Kinesis

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var example = new Aws.Lambda.EventSourceMapping("example", new Aws.Lambda.EventSourceMappingArgs
    {
        EventSourceArn = aws_kinesis_stream.Example.Arn,
        FunctionName = aws_lambda_function.Example.Arn,
        StartingPosition = "LATEST",
    });
}

}

SQS

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var example = new Aws.Lambda.EventSourceMapping("example", new Aws.Lambda.EventSourceMappingArgs
    {
        EventSourceArn = aws_sqs_queue.Sqs_queue_test.Arn,
        FunctionName = aws_lambda_function.Example.Arn,
    });
}

}

EventSourceMappingArgs

EventSourceMappingState

Function

Provides a Lambda Function resource. Lambda allows you to trigger execution of code in response to events in AWS, enabling serverless backend solutions. The Lambda Function itself includes source code and runtime configuration.

For information about Lambda and how to use it, see What is AWS Lambda?

NOTE: Due to AWS Lambda improved VPC networking changes that began deploying in September 2019, EC2 subnets and security groups associated with Lambda Functions can take up to 45 minutes to successfully delete.

Example Usage

Lambda Layers

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var exampleLayerVersion = new Aws.Lambda.LayerVersion("exampleLayerVersion", new Aws.Lambda.LayerVersionArgs
    {
    });
    var exampleFunction = new Aws.Lambda.Function("exampleFunction", new Aws.Lambda.FunctionArgs
    {
        Layers = 
        {
            exampleLayerVersion.Arn,
        },
    });
}

}

CloudWatch Logging and Permissions

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var testLambda = new Aws.Lambda.Function("testLambda", new Aws.Lambda.FunctionArgs
    {
    });
    // This is to optionally manage the CloudWatch Log Group for the Lambda Function.
    // If skipping this resource configuration, also add "logs:CreateLogGroup" to the IAM policy below.
    var example = new Aws.CloudWatch.LogGroup("example", new Aws.CloudWatch.LogGroupArgs
    {
        RetentionInDays = 14,
    });
    // See also the following AWS managed policy: AWSLambdaBasicExecutionRole
    var lambdaLogging = new Aws.Iam.Policy("lambdaLogging", new Aws.Iam.PolicyArgs
    {
        Description = "IAM policy for logging from a lambda",
        Path = "/",
        Policy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
  ""Action"": [
    ""logs:CreateLogGroup"",
    ""logs:CreateLogStream"",
    ""logs:PutLogEvents""
  ],
  ""Resource"": ""arn:aws:logs:*:*:*"",
  ""Effect"": ""Allow""
}
]
}

",
    });
    var lambdaLogs = new Aws.Iam.RolePolicyAttachment("lambdaLogs", new Aws.Iam.RolePolicyAttachmentArgs
    {
        PolicyArn = lambdaLogging.Arn,
        Role = aws_iam_role.Iam_for_lambda.Name,
    });
}

}

Specifying the Deployment Package

AWS Lambda expects source code to be provided as a deployment package whose structure varies depending on which runtime is in use. See Runtimes for the valid values of runtime. The expected structure of the deployment package can be found in the AWS Lambda documentation for each runtime.

Once you have created your deployment package you can specify it either directly as a local file (using the filename argument) or indirectly via Amazon S3 (using the s3_bucket, s3_key and s3_object_version arguments). When providing the deployment package via S3 it may be useful to use the aws.s3.BucketObject resource to upload it.

For larger deployment packages it is recommended by Amazon to upload via S3, since the S3 API has better support for uploading large files efficiently.

FunctionArgs

FunctionEventInvokeConfig

Manages an asynchronous invocation configuration for a Lambda Function or Alias. More information about asynchronous invocations and the configurable values can be found in the Lambda Developer Guide.

Example Usage

Error Handling Configuration

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var example = new Aws.Lambda.FunctionEventInvokeConfig("example", new Aws.Lambda.FunctionEventInvokeConfigArgs
    {
        FunctionName = aws_lambda_alias.Example.Function_name,
        MaximumEventAgeInSeconds = 60,
        MaximumRetryAttempts = 0,
    });
}

}

Configuration for Alias Name

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var example = new Aws.Lambda.FunctionEventInvokeConfig("example", new Aws.Lambda.FunctionEventInvokeConfigArgs
    {
        FunctionName = aws_lambda_alias.Example.Function_name,
        Qualifier = aws_lambda_alias.Example.Name,
    });
    // ... other configuration ...
}

}

Configuration for Function Latest Unpublished Version

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var example = new Aws.Lambda.FunctionEventInvokeConfig("example", new Aws.Lambda.FunctionEventInvokeConfigArgs
    {
        FunctionName = aws_lambda_function.Example.Function_name,
        Qualifier = "$LATEST",
    });
    // ... other configuration ...
}

}

Configuration for Function Published Version

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var example = new Aws.Lambda.FunctionEventInvokeConfig("example", new Aws.Lambda.FunctionEventInvokeConfigArgs
    {
        FunctionName = aws_lambda_function.Example.Function_name,
        Qualifier = aws_lambda_function.Example.Version,
    });
    // ... other configuration ...
}

}

FunctionEventInvokeConfigArgs

FunctionEventInvokeConfigState

FunctionState

GetAlias

GetAliasArgs

GetAliasResult

GetFunction

GetFunctionArgs

GetFunctionResult

GetInvocation

GetInvocationArgs

GetInvocationResult

GetLayerVersion

GetLayerVersionArgs

GetLayerVersionResult

LayerVersion

Provides a Lambda Layer Version resource. Lambda Layers allow you to reuse shared bits of code across multiple lambda functions.

For information about Lambda Layers and how to use them, see AWS Lambda Layers

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var lambdaLayer = new Aws.Lambda.LayerVersion("lambdaLayer", new Aws.Lambda.LayerVersionArgs
    {
        CompatibleRuntimes = 
        {
            "nodejs8.10",
        },
        Code = new FileArchive("lambda_layer_payload.zip"),
        LayerName = "lambda_layer_name",
    });
}

}

Specifying the Deployment Package

AWS Lambda Layers expect source code to be provided as a deployment package whose structure varies depending on which compatible_runtimes this layer specifies. See Runtimes for the valid values of compatible_runtimes.

Once you have created your deployment package you can specify it either directly as a local file (using the filename argument) or indirectly via Amazon S3 (using the s3_bucket, s3_key and s3_object_version arguments). When providing the deployment package via S3 it may be useful to use the aws.s3.BucketObject resource to upload it.

For larger deployment packages it is recommended by Amazon to upload via S3, since the S3 API has better support for uploading large files efficiently.

LayerVersionArgs

LayerVersionState

Permission

Creates a Lambda permission to allow external sources invoking the Lambda function (e.g. CloudWatch Event Rule, SNS or S3).

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var iamForLambda = new Aws.Iam.Role("iamForLambda", new Aws.Iam.RoleArgs
    {
        AssumeRolePolicy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
  ""Action"": ""sts:AssumeRole"",
  ""Principal"": {
    ""Service"": ""lambda.amazonaws.com""
  },
  ""Effect"": ""Allow"",
  ""Sid"": """"
}
]
}

",
    });
    var testLambda = new Aws.Lambda.Function("testLambda", new Aws.Lambda.FunctionArgs
    {
        Code = new FileArchive("lambdatest.zip"),
        Handler = "exports.handler",
        Role = iamForLambda.Arn,
        Runtime = "nodejs8.10",
    });
    var testAlias = new Aws.Lambda.Alias("testAlias", new Aws.Lambda.AliasArgs
    {
        Description = "a sample description",
        FunctionName = testLambda.Name,
        FunctionVersion = "$$LATEST",
    });
    var allowCloudwatch = new Aws.Lambda.Permission("allowCloudwatch", new Aws.Lambda.PermissionArgs
    {
        Action = "lambda:InvokeFunction",
        Function = testLambda.Name,
        Principal = "events.amazonaws.com",
        Qualifier = testAlias.Name,
        SourceArn = "arn:aws:events:eu-west-1:111122223333:rule/RunDaily",
    });
}

}

Usage with SNS

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var defaultTopic = new Aws.Sns.Topic("defaultTopic", new Aws.Sns.TopicArgs
    {
    });
    var defaultRole = new Aws.Iam.Role("defaultRole", new Aws.Iam.RoleArgs
    {
        AssumeRolePolicy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
  ""Action"": ""sts:AssumeRole"",
  ""Principal"": {
    ""Service"": ""lambda.amazonaws.com""
  },
  ""Effect"": ""Allow"",
  ""Sid"": """"
}
]
}

",
    });
    var func = new Aws.Lambda.Function("func", new Aws.Lambda.FunctionArgs
    {
        Code = new FileArchive("lambdatest.zip"),
        Handler = "exports.handler",
        Role = defaultRole.Arn,
        Runtime = "python2.7",
    });
    var withSns = new Aws.Lambda.Permission("withSns", new Aws.Lambda.PermissionArgs
    {
        Action = "lambda:InvokeFunction",
        Function = func.Name,
        Principal = "sns.amazonaws.com",
        SourceArn = defaultTopic.Arn,
    });
    var lambda = new Aws.Sns.TopicSubscription("lambda", new Aws.Sns.TopicSubscriptionArgs
    {
        Endpoint = func.Arn,
        Protocol = "lambda",
        Topic = defaultTopic.Arn,
    });
}

}

Specify Lambda permissions for API Gateway REST API

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var myDemoAPI = new Aws.ApiGateway.RestApi("myDemoAPI", new Aws.ApiGateway.RestApiArgs
    {
        Description = "This is my API for demonstration purposes",
    });
    var lambdaPermission = new Aws.Lambda.Permission("lambdaPermission", new Aws.Lambda.PermissionArgs
    {
        Action = "lambda:InvokeFunction",
        Function = "MyDemoFunction",
        Principal = "apigateway.amazonaws.com",
        SourceArn = myDemoAPI.ExecutionArn.Apply(executionArn => $"{executionArn}/*/*/*"),
    });
}

}

PermissionArgs

PermissionState

ProvisionedConcurrencyConfig

Manages a Lambda Provisioned Concurrency Configuration.

Example Usage

Alias Name

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var example = new Aws.Lambda.ProvisionedConcurrencyConfig("example", new Aws.Lambda.ProvisionedConcurrencyConfigArgs
    {
        FunctionName = aws_lambda_alias.Example.Function_name,
        ProvisionedConcurrentExecutions = 1,
        Qualifier = aws_lambda_alias.Example.Name,
    });
}

}

Function Version

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var example = new Aws.Lambda.ProvisionedConcurrencyConfig("example", new Aws.Lambda.ProvisionedConcurrencyConfigArgs
    {
        FunctionName = aws_lambda_function.Example.Function_name,
        ProvisionedConcurrentExecutions = 1,
        Qualifier = aws_lambda_function.Example.Version,
    });
}

}

ProvisionedConcurrencyConfigArgs

ProvisionedConcurrencyConfigState

Back to top Copyright 2016-2020, Pulumi Corporation.