【问题标题】:How to write a JSON object to a .json file in S3, using Lambda(python)?如何使用 Lambda(python) 将 JSON 对象写入 S3 中的 .json 文件?
【发布时间】:2021-06-11 07:43:56
【问题描述】:

因此,在我的 Lambda 函数中,我将数据转换为 JSON 对象:

x=json.dumps(my_data)

现在,我想将对象 x 存储为 S3 中的 .json 文件。我如何做到这一点?

【问题讨论】:

    标签: amazon-web-services amazon-s3 aws-lambda


    【解决方案1】:

    Write-S3Object cmdlet 支持将内嵌文本内容上传到 Amazon S3 的功能。使用 -Content 参数(别名 -Text),您可以指定应上传到 Amazon S3 的基于文本的内容,而无需先将其放入文件中。该参数接受简单的单行字符串以及此处包含多行的字符串。

    PS > # Specifying content in-line, single line text:
    PS > write-s3object mybucket -key myobject.txt -content "file content"
    
    PS > # Specifying content in-line, multi-line text: (note final newline needed to end in-line here-string)
    PS > write-s3object mybucket -key myobject.txt -content @"
    >> line 1
    >> line 2
    >> line 3
    >> "@
    >> 
    PS > # Specifying content from a variable: (note final newline needed to end in-line here-string)
    PS > $x = @"
    >> line 1
    >> line 2
    >> line 3
    >> "@
    >> 
    PS > write-s3object mybucket -key myobject.txt -content $x
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 1970-01-01
      • 2020-03-30
      • 2018-08-03
      • 2021-09-07
      • 1970-01-01
      • 2021-01-27
      相关资源
      最近更新 更多