Class EventSourceMapping


  • public class EventSourceMapping
    extends com.pulumi.resources.CustomResource
    Provides a Lambda event source mapping. This allows Lambda functions to get events from Kinesis, DynamoDB, SQS, Amazon MQ and Managed Streaming for Apache Kafka (MSK). For information about Lambda and how to use it, see [What is AWS Lambda?](http://docs.aws.amazon.com/lambda/latest/dg/welcome.html). For information about event source mappings, see [CreateEventSourceMapping](http://docs.aws.amazon.com/lambda/latest/dg/API_CreateEventSourceMapping.html) in the API docs. ## Example Usage ### DynamoDB ```java package generated_program; import java.util.*; import java.io.*; import java.nio.*; import com.pulumi.*; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var example = new EventSourceMapping("example", EventSourceMappingArgs.builder() .eventSourceArn(aws_dynamodb_table.example().stream_arn()) .functionName(aws_lambda_function.example().arn()) .startingPosition("LATEST") .build()); } } ``` ### Kinesis ```java package generated_program; import java.util.*; import java.io.*; import java.nio.*; import com.pulumi.*; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var example = new EventSourceMapping("example", EventSourceMappingArgs.builder() .eventSourceArn(aws_kinesis_stream.example().arn()) .functionName(aws_lambda_function.example().arn()) .startingPosition("LATEST") .build()); } } ``` ### Managed Streaming for Apache Kafka (MSK) ```java package generated_program; import java.util.*; import java.io.*; import java.nio.*; import com.pulumi.*; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var example = new EventSourceMapping("example", EventSourceMappingArgs.builder() .eventSourceArn(aws_msk_cluster.example().arn()) .functionName(aws_lambda_function.example().arn()) .topics("Example") .startingPosition("TRIM_HORIZON") .build()); } } ``` ### Self Managed Apache Kafka ```java package generated_program; import java.util.*; import java.io.*; import java.nio.*; import com.pulumi.*; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var example = new EventSourceMapping("example", EventSourceMappingArgs.builder() .functionName(aws_lambda_function.example().arn()) .topics("Example") .startingPosition("TRIM_HORIZON") .selfManagedEventSource(EventSourceMappingSelfManagedEventSourceArgs.builder() .endpoints(Map.of("KAFKA_BOOTSTRAP_SERVERS", "kafka1.example.com:9092,kafka2.example.com:9092")) .build()) .sourceAccessConfigurations( EventSourceMappingSourceAccessConfigurationArgs.builder() .type("VPC_SUBNET") .uri("subnet:subnet-example1") .build(), EventSourceMappingSourceAccessConfigurationArgs.builder() .type("VPC_SUBNET") .uri("subnet:subnet-example2") .build(), EventSourceMappingSourceAccessConfigurationArgs.builder() .type("VPC_SECURITY_GROUP") .uri("security_group:sg-example") .build()) .build()); } } ``` ### SQS ```java package generated_program; import java.util.*; import java.io.*; import java.nio.*; import com.pulumi.*; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var example = new EventSourceMapping("example", EventSourceMappingArgs.builder() .eventSourceArn(aws_sqs_queue.sqs_queue_test().arn()) .functionName(aws_lambda_function.example().arn()) .build()); } } ``` ### SQS with event filter ```java package generated_program; import java.util.*; import java.io.*; import java.nio.*; import com.pulumi.*; import static com.pulumi.codegen.internal.Serialization.*; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var example = new EventSourceMapping("example", EventSourceMappingArgs.builder() .eventSourceArn(aws_sqs_queue.sqs_queue_test().arn()) .functionName(aws_lambda_function.example().arn()) .filterCriteria(EventSourceMappingFilterCriteriaArgs.builder() .filters(EventSourceMappingFilterCriteriaFilterArgs.builder() .pattern(serializeJson( jsonObject( jsonProperty("body", jsonObject( jsonProperty("Temperature", jsonArray(jsonObject( jsonProperty("numeric", jsonArray( ">", 0, "<=", 100 )) ))), jsonProperty("Location", jsonArray("New York")) )) ))) .build()) .build()) .build()); } } ``` ### Amazon MQ (ActiveMQ) ```java package generated_program; import java.util.*; import java.io.*; import java.nio.*; import com.pulumi.*; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var example = new EventSourceMapping("example", EventSourceMappingArgs.builder() .batchSize(10) .eventSourceArn(aws_mq_broker.example().arn()) .enabled(true) .functionName(aws_lambda_function.example().arn()) .queues("example") .sourceAccessConfigurations(EventSourceMappingSourceAccessConfigurationArgs.builder() .type("BASIC_AUTH") .uri(aws_secretsmanager_secret_version.example().arn()) .build()) .build()); } } ``` ### Amazon MQ (RabbitMQ) ```java package generated_program; import java.util.*; import java.io.*; import java.nio.*; import com.pulumi.*; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var example = new EventSourceMapping("example", EventSourceMappingArgs.builder() .batchSize(1) .eventSourceArn(aws_mq_broker.example().arn()) .enabled(true) .functionName(aws_lambda_function.example().arn()) .queues("example") .sourceAccessConfigurations( EventSourceMappingSourceAccessConfigurationArgs.builder() .type("VIRTUAL_HOST") .uri("/example") .build(), EventSourceMappingSourceAccessConfigurationArgs.builder() .type("BASIC_AUTH") .uri(aws_secretsmanager_secret_version.example().arn()) .build()) .build()); } } ``` ### Managed Streaming for Kafka (MSK) ```java package generated_program; import java.util.*; import java.io.*; import java.nio.*; import com.pulumi.*; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var example = new EventSourceMapping("example", EventSourceMappingArgs.builder() .eventSourceArn(aws_msk_cluster.example().arn()) .functionName(aws_lambda_function.example().arn()) .topics("Example") .startingPosition("TRIM_HORIZON") .build()); } } ``` ## Import Lambda event source mappings can be imported using the `UUID` (event source mapping identifier), e.g., ```sh $ pulumi import aws:lambda/eventSourceMapping:EventSourceMapping event_source_mapping 12345kxodurf3443 ```
    • Constructor Detail

      • EventSourceMapping

        public EventSourceMapping​(java.lang.String name)
        Parameters:
        name - The _unique_ name of the resulting resource.
      • EventSourceMapping

        public EventSourceMapping​(java.lang.String name,
                                  EventSourceMappingArgs args)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
      • EventSourceMapping

        public EventSourceMapping​(java.lang.String name,
                                  EventSourceMappingArgs args,
                                  @Nullable
                                  com.pulumi.resources.CustomResourceOptions options)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
        options - A bag of options that control this resource's behavior.
    • Method Detail

      • batchSize

        public com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> batchSize()
        Returns:
        The largest number of records that Lambda will retrieve from your event source at the time of invocation. Defaults to `100` for DynamoDB, Kinesis, MQ and MSK, `10` for SQS. * `bisect_batch_on_function_error`: - (Optional) If the function returns an error, split the batch in two and retry. Only available for stream sources (DynamoDB and Kinesis). Defaults to `false`. * `destination_config`: - (Optional) An Amazon SQS queue or Amazon SNS topic destination for failed records. Only available for stream sources (DynamoDB and Kinesis). Detailed below.
      • bisectBatchOnFunctionError

        public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> bisectBatchOnFunctionError()
      • enabled

        public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> enabled()
        Returns:
        Determines if the mapping will be enabled on creation. Defaults to `true`.
      • eventSourceArn

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> eventSourceArn()
        Returns:
        The event source ARN - this is required for Kinesis stream, DynamoDB stream, SQS queue, MQ broker or MSK cluster. It is incompatible with a Self Managed Kafka source.
      • filterCriteria

        public com.pulumi.core.Output<java.util.Optional<EventSourceMappingFilterCriteria>> filterCriteria()
        Returns:
        The criteria to use for [event filtering](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html) Kinesis stream, DynamoDB stream, SQS queue event sources. Detailed below.
      • functionArn

        public com.pulumi.core.Output<java.lang.String> functionArn()
        Returns:
        The the ARN of the Lambda function the event source mapping is sending events to. (Note: this is a computed value that differs from `function_name` above.)
      • functionName

        public com.pulumi.core.Output<java.lang.String> functionName()
        Returns:
        The name or the ARN of the Lambda function that will be subscribing to events.
      • functionResponseTypes

        public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> functionResponseTypes()
        Returns:
        A list of current response type enums applied to the event source mapping for [AWS Lambda checkpointing](https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#services-ddb-batchfailurereporting). Only available for SQS and stream sources (DynamoDB and Kinesis). Valid values: `ReportBatchItemFailures`.
      • lastModified

        public com.pulumi.core.Output<java.lang.String> lastModified()
        Returns:
        The date this resource was last modified.
      • lastProcessingResult

        public com.pulumi.core.Output<java.lang.String> lastProcessingResult()
        Returns:
        The result of the last AWS Lambda invocation of your Lambda function.
      • maximumBatchingWindowInSeconds

        public com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> maximumBatchingWindowInSeconds()
        Returns:
        The maximum amount of time to gather records before invoking the function, in seconds (between 0 and 300). Records will continue to buffer (or accumulate in the case of an SQS queue event source) until either `maximum_batching_window_in_seconds` expires or `batch_size` has been met. For streaming event sources, defaults to as soon as records are available in the stream. If the batch it reads from the stream/queue only has one record in it, Lambda only sends one record to the function. Only available for stream sources (DynamoDB and Kinesis) and SQS standard queues. * `maximum_record_age_in_seconds`: - (Optional) The maximum age of a record that Lambda sends to a function for processing. Only available for stream sources (DynamoDB and Kinesis). Must be either -1 (forever, and the default value) or between 60 and 604800 (inclusive). * `maximum_retry_attempts`: - (Optional) The maximum number of times to retry when the function returns an error. Only available for stream sources (DynamoDB and Kinesis). Minimum and default of -1 (forever), maximum of 10000. * `parallelization_factor`: - (Optional) The number of batches to process from each shard concurrently. Only available for stream sources (DynamoDB and Kinesis). Minimum and default of 1, maximum of 10.
      • maximumRecordAgeInSeconds

        public com.pulumi.core.Output<java.lang.Integer> maximumRecordAgeInSeconds()
      • maximumRetryAttempts

        public com.pulumi.core.Output<java.lang.Integer> maximumRetryAttempts()
      • parallelizationFactor

        public com.pulumi.core.Output<java.lang.Integer> parallelizationFactor()
      • queues

        public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> queues()
        Returns:
        The name of the Amazon MQ broker destination queue to consume. Only available for MQ sources. A single queue name must be specified. * `self_managed_event_source`: - (Optional) For Self Managed Kafka sources, the location of the self managed cluster. If set, configuration must also include `source_access_configuration`. Detailed below. * `source_access_configuration`: (Optional) For Self Managed Kafka sources, the access configuration for the source. If set, configuration must also include `self_managed_event_source`. Detailed below.
      • startingPosition

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> startingPosition()
        Returns:
        The position in the stream where AWS Lambda should start reading. Must be one of `AT_TIMESTAMP` (Kinesis only), `LATEST` or `TRIM_HORIZON` if getting events from Kinesis, DynamoDB or MSK. Must not be provided if getting events from SQS. More information about these positions can be found in the [AWS DynamoDB Streams API Reference](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_GetShardIterator.html) and [AWS Kinesis API Reference](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html#Kinesis-GetShardIterator-request-ShardIteratorType).
      • startingPositionTimestamp

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> startingPositionTimestamp()
        Returns:
        A timestamp in [RFC3339 format](https://tools.ietf.org/html/rfc3339#section-5.8) of the data record which to start reading when using `starting_position` set to `AT_TIMESTAMP`. If a record with this exact timestamp does not exist, the next later record is chosen. If the timestamp is older than the current trim horizon, the oldest available record is chosen.
      • state

        public com.pulumi.core.Output<java.lang.String> state()
        Returns:
        The state of the event source mapping.
      • stateTransitionReason

        public com.pulumi.core.Output<java.lang.String> stateTransitionReason()
        Returns:
        The reason the event source mapping is in its current state.
      • topics

        public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> topics()
        Returns:
        The name of the Kafka topics. Only available for MSK sources. A single topic name must be specified.
      • tumblingWindowInSeconds

        public com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> tumblingWindowInSeconds()
        Returns:
        The duration in seconds of a processing window for [AWS Lambda streaming analytics](https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html#services-kinesis-windows). The range is between 1 second up to 900 seconds. Only available for stream sources (DynamoDB and Kinesis).
      • uuid

        public com.pulumi.core.Output<java.lang.String> uuid()
        Returns:
        The UUID of the created event source mapping.
      • get

        public static EventSourceMapping get​(java.lang.String name,
                                             com.pulumi.core.Output<java.lang.String> id,
                                             @Nullable
                                             EventSourceMappingState state,
                                             @Nullable
                                             com.pulumi.resources.CustomResourceOptions options)
        Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
        Parameters:
        name - The _unique_ name of the resulting resource.
        id - The _unique_ provider ID of the resource to lookup.
        state -
        options - Optional settings to control the behavior of the CustomResource.