【问题标题】:Creating AWS S3 object life cycle using NodeJS使用 NodeJS 创建 AWS S3 对象生命周期
【发布时间】:2021-05-23 01:48:03
【问题描述】:

使用 NodeJS 创建 AWS S3 对象生命周期。

我想使用 NodeJS 通过 API 创建 S3 对象生命周期。当我看到文档时,AWS 只提供了多个对象生命周期,使用 Java。

https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-set-lifecycle-configuration-intro.html

我也检查了这个网址 -

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getBucketLifecycle-property

普遍关注

如何像Java一样用NodeJS设置多个Transition?

BucketLifecycleConfiguration.Rule rule2 = new BucketLifecycleConfiguration.Rule()
                .withId("Archive and then delete rule")
                .withFilter(new LifecycleFilter(new LifecycleTagPredicate(new Tag("archive", "true"))))
                .addTransition(new Transition().withDays(30).withStorageClass(StorageClass.StandardInfrequentAccess))
                .addTransition(new Transition().withDays(365).withStorageClass(StorageClass.Glacier))
                .withExpirationInDays(3650)
                .withStatus(BucketLifecycleConfiguration.ENABLED);

接着 - https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-set-lifecycle-configuration-intro.html

任何帮助都会很棒。

【问题讨论】:

    标签: node.js amazon-web-services amazon-s3 aws-sdk awss3transfermanager


    【解决方案1】:

    我们需要调用putBucketLifecycle 并将Rules 数组传递给LifecycleConfiguration。类似于CLI Example

    s3.putBucketLifecycle(
      {
        Bucket: "sample-temp-bucket",
        LifecycleConfiguration: {
          Rules: [
            {
              Filter: {
                And: {
                  Prefix: "myprefix",
                  Tags: [
                    {
                      Value: "mytagvalue1",
                      Key: "mytagkey1",
                    },
                    {
                      Value: "mytagvalue2",
                      Key: "mytagkey2",
                    },
                  ],
                },
              },
              Status: "Enabled",
              Expiration: {
                Days: 1,
              },
            },
            {
              Filter: {
                Prefix: "documents/",
              },
              Status: "Enabled",
              Transitions: [
                {
                  Days: 365,
                  StorageClass: "GLACIER",
                },
              ],
              Expiration: {
                Days: 3650,
              },
              ID: "ExampleRule",
            },
          ],
        },
      },
      (error, result) => {
        if (error) console.log("error", error);
        if (result) console.log("result", result);
      }
    );
    

    【讨论】:

    • 谢谢。 @balu
    • 很高兴我能帮上忙。如果此答案解决了您的问题,请考虑投票和/或accepting。
    猜你喜欢
    • 2019-05-06
    • 2021-06-29
    • 2016-07-31
    • 2014-12-22
    • 1970-01-01
    • 2018-09-18
    • 2021-12-28
    • 2021-06-14
    • 1970-01-01
    相关资源
    最近更新 更多