github.com/Jeffail/benthos/v3@v3.65.0/lib/output/aws_dynamodb.go (about)

     1  package output
     2  
     3  import (
     4  	"github.com/Jeffail/benthos/v3/internal/docs"
     5  	"github.com/Jeffail/benthos/v3/lib/log"
     6  	"github.com/Jeffail/benthos/v3/lib/message/batch"
     7  	"github.com/Jeffail/benthos/v3/lib/metrics"
     8  	"github.com/Jeffail/benthos/v3/lib/output/writer"
     9  	"github.com/Jeffail/benthos/v3/lib/types"
    10  	"github.com/Jeffail/benthos/v3/lib/util/aws/session"
    11  	"github.com/Jeffail/benthos/v3/lib/util/retries"
    12  )
    13  
    14  //------------------------------------------------------------------------------
    15  
    16  func init() {
    17  	Constructors[TypeAWSDynamoDB] = TypeSpec{
    18  		constructor: fromSimpleConstructor(NewAWSDynamoDB),
    19  		Version:     "3.36.0",
    20  		Summary: `
    21  Inserts items into a DynamoDB table.`,
    22  		Description: `
    23  The field ` + "`string_columns`" + ` is a map of column names to string values,
    24  where the values are
    25  [function interpolated](/docs/configuration/interpolation#bloblang-queries) per message of a
    26  batch. This allows you to populate string columns of an item by extracting
    27  fields within the document payload or metadata like follows:
    28  
    29  ` + "```yaml" + `
    30  string_columns:
    31    id: ${!json("id")}
    32    title: ${!json("body.title")}
    33    topic: ${!meta("kafka_topic")}
    34    full_content: ${!content()}
    35  ` + "```" + `
    36  
    37  The field ` + "`json_map_columns`" + ` is a map of column names to json paths,
    38  where the [dot path](/docs/configuration/field_paths) is extracted from each document and
    39  converted into a map value. Both an empty path and the path ` + "`.`" + ` are
    40  interpreted as the root of the document. This allows you to populate map columns
    41  of an item like follows:
    42  
    43  ` + "```yml" + `
    44  json_map_columns:
    45    user: path.to.user
    46    whole_document: .
    47  ` + "```" + `
    48  
    49  A column name can be empty:
    50  
    51  ` + "```yml" + `
    52  json_map_columns:
    53    "": .
    54  ` + "```" + `
    55  
    56  In which case the top level document fields will be written at the root of the
    57  item, potentially overwriting previously defined column values. If a path is not
    58  found within a document the column will not be populated.
    59  
    60  ### Credentials
    61  
    62  By default Benthos will use a shared credentials file when connecting to AWS
    63  services. It's also possible to set them explicitly at the component level,
    64  allowing you to transfer data across accounts. You can find out more
    65  [in this document](/docs/guides/cloud/aws).`,
    66  		Async:   true,
    67  		Batches: true,
    68  		FieldSpecs: docs.FieldSpecs{
    69  			docs.FieldCommon("table", "The table to store messages in."),
    70  			docs.FieldString("string_columns", "A map of column keys to string values to store.",
    71  				map[string]string{
    72  					"id":           "${!json(\"id\")}",
    73  					"title":        "${!json(\"body.title\")}",
    74  					"topic":        "${!meta(\"kafka_topic\")}",
    75  					"full_content": "${!content()}",
    76  				},
    77  			).IsInterpolated().Map(),
    78  			docs.FieldString("json_map_columns", "A map of column keys to [field paths](/docs/configuration/field_paths) pointing to value data within messages.",
    79  				map[string]string{
    80  					"user":           "path.to.user",
    81  					"whole_document": ".",
    82  				},
    83  				map[string]string{
    84  					"": ".",
    85  				},
    86  			).Map(),
    87  			docs.FieldAdvanced("ttl", "An optional TTL to set for items, calculated from the moment the message is sent."),
    88  			docs.FieldAdvanced("ttl_key", "The column key to place the TTL value within."),
    89  			docs.FieldCommon("max_in_flight", "The maximum number of messages to have in flight at a given time. Increase this to improve throughput."),
    90  			batch.FieldSpec(),
    91  		}.Merge(session.FieldSpecs()).Merge(retries.FieldSpecs()),
    92  		Categories: []Category{
    93  			CategoryServices,
    94  			CategoryAWS,
    95  		},
    96  	}
    97  
    98  	Constructors[TypeDynamoDB] = TypeSpec{
    99  		constructor: fromSimpleConstructor(NewDynamoDB),
   100  		Status:      docs.StatusDeprecated,
   101  		Summary: `
   102  Inserts items into a DynamoDB table.`,
   103  		Description: `
   104  ## Alternatives
   105  
   106  This output has been renamed to ` + "[`aws_dynamodb`](/docs/components/outputs/aws_dynamodb)" + `.
   107  
   108  The field ` + "`string_columns`" + ` is a map of column names to string values,
   109  where the values are
   110  [function interpolated](/docs/configuration/interpolation#bloblang-queries) per message of a
   111  batch. This allows you to populate string columns of an item by extracting
   112  fields within the document payload or metadata like follows:
   113  
   114  ` + "```yml" + `
   115  string_columns:
   116    id: ${!json("id")}
   117    title: ${!json("body.title")}
   118    topic: ${!meta("kafka_topic")}
   119    full_content: ${!content()}
   120  ` + "```" + `
   121  
   122  The field ` + "`json_map_columns`" + ` is a map of column names to json paths,
   123  where the [dot path](/docs/configuration/field_paths) is extracted from each document and
   124  converted into a map value. Both an empty path and the path ` + "`.`" + ` are
   125  interpreted as the root of the document. This allows you to populate map columns
   126  of an item like follows:
   127  
   128  ` + "```yml" + `
   129  json_map_columns:
   130    user: path.to.user
   131    whole_document: .
   132  ` + "```" + `
   133  
   134  A column name can be empty:
   135  
   136  ` + "```yml" + `
   137  json_map_columns:
   138    "": .
   139  ` + "```" + `
   140  
   141  In which case the top level document fields will be written at the root of the
   142  item, potentially overwriting previously defined column values. If a path is not
   143  found within a document the column will not be populated.
   144  
   145  ### Credentials
   146  
   147  By default Benthos will use a shared credentials file when connecting to AWS
   148  services. It's also possible to set them explicitly at the component level,
   149  allowing you to transfer data across accounts. You can find out more
   150  [in this document](/docs/guides/cloud/aws).`,
   151  		Async:   true,
   152  		Batches: true,
   153  		FieldSpecs: docs.FieldSpecs{
   154  			docs.FieldCommon("table", "The table to store messages in."),
   155  			docs.FieldCommon("string_columns", "A map of column keys to string values to store.",
   156  				map[string]string{
   157  					"id":           "${!json(\"id\")}",
   158  					"title":        "${!json(\"body.title\")}",
   159  					"topic":        "${!meta(\"kafka_topic\")}",
   160  					"full_content": "${!content()}",
   161  				},
   162  			).IsInterpolated().Map(),
   163  			docs.FieldCommon("json_map_columns", "A map of column keys to [field paths](/docs/configuration/field_paths) pointing to value data within messages.",
   164  				map[string]string{
   165  					"user":           "path.to.user",
   166  					"whole_document": ".",
   167  				},
   168  				map[string]string{
   169  					"": ".",
   170  				},
   171  			).Map(),
   172  			docs.FieldAdvanced("ttl", "An optional TTL to set for items, calculated from the moment the message is sent."),
   173  			docs.FieldAdvanced("ttl_key", "The column key to place the TTL value within."),
   174  			docs.FieldCommon("max_in_flight", "The maximum number of messages to have in flight at a given time. Increase this to improve throughput."),
   175  			batch.FieldSpec(),
   176  		}.Merge(session.FieldSpecs()).Merge(retries.FieldSpecs()),
   177  		Categories: []Category{
   178  			CategoryServices,
   179  			CategoryAWS,
   180  		},
   181  	}
   182  }
   183  
   184  //------------------------------------------------------------------------------
   185  
   186  // NewAWSDynamoDB creates a new DynamoDB output type.
   187  func NewAWSDynamoDB(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
   188  	return newDynamoDB(TypeAWSDynamoDB, conf.AWSDynamoDB, mgr, log, stats)
   189  }
   190  
   191  // NewDynamoDB creates a new DynamoDB output type.
   192  func NewDynamoDB(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
   193  	return newDynamoDB(TypeDynamoDB, conf.DynamoDB, mgr, log, stats)
   194  }
   195  
   196  func newDynamoDB(name string, conf writer.DynamoDBConfig, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
   197  	dyn, err := writer.NewDynamoDBV2(conf, mgr, log, stats)
   198  	if err != nil {
   199  		return nil, err
   200  	}
   201  	var w Type
   202  	if conf.MaxInFlight == 1 {
   203  		w, err = NewWriter(name, dyn, log, stats)
   204  	} else {
   205  		w, err = NewAsyncWriter(name, conf.MaxInFlight, dyn, log, stats)
   206  	}
   207  	if err != nil {
   208  		return w, err
   209  	}
   210  	return NewBatcherFromConfig(conf.Batching, w, mgr, log, stats)
   211  }
   212  
   213  //------------------------------------------------------------------------------