Lambda使用CDK上传文件?

huangapple go评论62阅读模式
英文:

Lambda upload files with cdk?

问题

我正在部署一个包含Lambda函数的CDK应用程序。我需要上传一个名为query.sql的文件,以便在调用Lambda函数时执行。

有没有一种方法可以指定在部署Lambda函数时需要上传的文件。

const Lambda = new lambda.Function(this, 'My_Function', {
      runtime: lambda.Runtime.PYTHON_3_9,
      handler: 'lambda.handler',
      code: lambda.Code.fromAsset(path.join(__dirname, '../handler')),
      architecture: lambda.Architecture.ARM_64,
      layers: [myLambda_layer]
}
英文:

I am deploying a cdk app that contains a lambda. I need to upload a file query.sql to be executed when the lambda is called.

Is there a way to specify files that needs to be uploaded when deploying the lambda.

const Lambda = new lambda.Function(this, 'My_Function', {
      runtime: lambda.Runtime.PYTHON_3_9,
      handler: 'lambda.handler',
      code: lambda.Code.fromAsset(path.join(__dirname, '../handler')),
      architecture: lambda.Architecture.ARM_64,
      layers: [myLambda_layer]
}

答案1

得分: 1

你可以将它们添加到与 lambda.py 文件位于相同目录中。然后,你可以使用Python的 open 函数从SQL文件中读取文本:

fd = open('./my-personal-script.sql', 'r')
sqlFile = fd.read()
fd.close()

print(sqlFile)
英文:

You can add them on the same directory where the lambda.py file is located at. You can then just read the text out of the SQL file using python's open function:

fd = open('./my-personal-script.sql', 'r')
sqlFile = fd.read()
fd.close()

print(sqlFile)

huangapple
  • 本文由 发表于 2023年7月3日 21:10:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605068.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定