我有两个文件:
MyLambdaFunction.py
config.json
Run Code Online (Sandbox Code Playgroud)
我将这两个压缩在一起创建MyLambdaFunction.zip.然后我通过AWS控制台将其上传到我的lambda函数.
config.json的内容是各种环境变量.我需要一种方法来在每次运行lambda函数时读取文件的内容,然后使用里面的数据来设置运行时变量.
如何让我的Python Lambda函数读取上传到zip文件中的源文件的文件config.json的内容?
我有一个很棒的 Paramiko Python 脚本来通过 SCP 协议传输文件。但我需要的是一个没有任何其他文件依赖项的单个文件 (script.py),因此我不想为我的 SSH 私钥使用外部文件。
我想做的是将私钥嵌入到字符串变量中,并使用该变量作为脚本连接所需的文件。我尝试使用StringIO图书馆,但它似乎不起作用:
hostname = '1.1.1.1' # remote hostname where SSH server is running
port = 22
username = 'user'
password = 'pswd'
dir_local='/home/paramikouser/local_data'
dir_remote = "remote_machine_folder/subfolder"
glob_pattern='*.*'
import os
import glob
import paramiko
import md5
import StringIO
private_key = StringIO.StringIO('-----BEGIN RSA PRIVATE KEY-----\n-----END RSA PRIVATE KEY-----')
def agent_auth(transport, username):
"""
Attempt to authenticate to the given transport using any of the private
keys available from an SSH agent or from …Run Code Online (Sandbox Code Playgroud)