【发布时间】:2020-01-16 21:11:51
【问题描述】:
我需要同步不同账户中的 s3 存储桶。为此,我使用存储桶策略创建 2 个存储桶,并使用 iam 策略和 s3 事件触发器创建 Lambda 函数。
我通过 CLI 尝试过。任何人都可以帮助编写机器人脚本来同步存储桶
我正在 lambda 中尝试以下代码-
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def sync_command(command):
command_list = command.split(' ')
try:
logger.info("Running shell command: \"{}\"".format(command))
result = subprocess.run(command_list, stdout=subprocess.PIPE);
logger.info("Command output:\n---\n{}\n---".format(result.stdout.decode('UTF-8')))
except Exception as e:
logger.error("Exception: {}".format(e))
return False
return True
def lambda_handler(event, context):
logger.info(event);
SOURCE_BUCKET = os.environ['source']
print('SOURCE_BUCKET:', SOURCE_BUCKET)
TARGET_BUCKET = os.environ['target']
print('TARGET_BUCKET:', TARGET_BUCKET)
sync_command("aws s3 sync s3://source-bucket/ s3://destination-bucket/")
但这显示错误异常:[Errno 2]没有这样的文件或目录:'aws':'aws
【问题讨论】:
标签: amazon-s3 aws-lambda boto3