diff --git a/plugins/out_s3/s3.c b/plugins/out_s3/s3.c index d6be65bb179..49b07b88588 100644 --- a/plugins/out_s3/s3.c +++ b/plugins/out_s3/s3.c @@ -88,6 +88,13 @@ static struct flb_aws_header content_md5_header = { .val_len = 0, }; +static struct flb_aws_header storage_class_header = { + .key = "x-amz-storage-class", + .key_len = 19, + .val = "", + .val_len = 0, +}; + static char *mock_error_response(char *error_env_var) { char *err_val = NULL; @@ -138,6 +145,9 @@ static int create_headers(struct flb_s3 *ctx, char *body_md5, struct flb_aws_hea if (body_md5 != NULL && strlen(body_md5)) { headers_len++; } + if (ctx->storage_class != NULL) { + headers_len++; + } if (headers_len == 0) { *num_headers = headers_len; *headers = s3_headers; @@ -170,6 +180,12 @@ static int create_headers(struct flb_s3 *ctx, char *body_md5, struct flb_aws_hea s3_headers[n] = content_md5_header; s3_headers[n].val = body_md5; s3_headers[n].val_len = strlen(body_md5); + n++; + } + if (ctx->storage_class != NULL) { + s3_headers[n] = storage_class_header; + s3_headers[n].val = ctx->storage_class; + s3_headers[n].val_len = strlen(ctx->storage_class); } *num_headers = headers_len; @@ -739,6 +755,16 @@ static int cb_s3_init(struct flb_output_instance *ins, ctx->content_type = (char *) tmp; } + tmp = flb_output_get_property("storage_class", ins); + if (tmp) { + if (ctx->use_put_object == FLB_FALSE) { + flb_plg_error(ctx->ins, + "use_put_object must be enabled when storage_class is specified"); + return -1; + } + ctx->storage_class = (char *) tmp; + } + if (ctx->insecure == FLB_FALSE) { ctx->client_tls = flb_tls_create(ins->tls_verify, ins->tls_debug, @@ -2383,6 +2409,14 @@ static struct flb_config_map config_map[] = { "key formatters all work as expected while this feature is set to true." }, + { + FLB_CONFIG_MAP_STR, "storage_class", NULL, + 0, FLB_FALSE, 0, + "Specify the storage class for S3 objects. This option can be enabled " + "when use_put_object is on. If this option is not specified, objects " + "will be stored with the default 'STANDARD' storage class." + }, + /* EOF */ {0} }; diff --git a/plugins/out_s3/s3.h b/plugins/out_s3/s3.h index bf3c1ba6d76..0e13fd2e50f 100644 --- a/plugins/out_s3/s3.h +++ b/plugins/out_s3/s3.h @@ -107,6 +107,7 @@ struct flb_s3 { char *sts_endpoint; char *canned_acl; char *content_type; + char *storage_class; char *log_key; char *external_id; int free_endpoint;