英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论