Python AWS lambda克隆git存储库并使zip无法在s3中上载

Python AWS lambda克隆git存储库并使zip无法在s3中上载,python,git,amazon-web-services,amazon-s3,aws-lambda,Python,Git,Amazon Web Services,Amazon S3,Aws Lambda,我想尝试克隆位于私有github中的git存储库。我可以看到,在添加Webhook并按照描述设置云形成之后 它正在向我的lambda发送请求。我可以通过以下方式克隆存储库,但无法创建存储库的zip并将其上载到s3,因为在Lambda中,我找不到存储库的位置,无法将其压缩并从该路径上载 import boto3 from botocore.vendored import requests import logging import base64 import os import shutil fr

我想尝试克隆位于私有github中的git存储库。我可以看到,在添加Webhook并按照描述设置云形成之后

它正在向我的lambda发送请求。我可以通过以下方式克隆存储库,但无法创建存储库的zip并将其上载到s3,因为在Lambda中,我找不到存储库的位置,无法将其压缩并从该路径上载

import boto3
from botocore.vendored import requests
import logging
import base64
import os
import shutil
from zipfile import ZipFile
from cStringIO import StringIO

# Set to False to allow self-signed/invalid ssl certificates
verify = False

logger = logging.getLogger()
logger.setLevel(logging.INFO)


s3_client = boto3.client('s3')


def lambda_handler(event, context):

   path        =   "/gitpull" 
   clone       =   "git clone https://username:pwd@site.com/scm/awsdemos/testrepo.git" 

# os.system("sshpass -p your_password ssh user_name@your_localhost")
  os.chdir(path) 

  os.system(clone) # Cloning
#   folder = "/gitpull"
#   logger.info(os.listdir(folder))

#   shutil.make_archive('Gitpull', 'zip', '/tmp')
   s3_archive_file = "Gitpull.zip" 

    # Create zip from /tmp dir without any common prefixes
   shutil.make_archive('Gitpull', 'zip', os.getcwd())
   logger.info("Uploading zip to S3://%s/%s" % ('gitpulls3', s3_archive_file))
   s3_client.upload_file(os.getcwd(), 'gitpulls3', s3_archive_file)
   logger.info('Upload Complete')

有什么好方法可以做到这一点吗?

将s3\u client.upload\u文件更改为以下代码:

s3 = boto3.resource('s3')
s3.meta.client.upload_file(os.getcwd() + "/" + s3_archive_file_name, 'mybucket', s3_archive_file_name)
检查我在Lambda函数上尝试过的以下代码:

import boto3
from botocore.vendored import requests
import logging
import base64
import os
import shutil
from zipfile import ZipFile

# Set to False to allow self-signed/invalid ssl certificates
verify = False

logger = logging.getLogger()
logger.setLevel(logging.INFO)

logging.info("hello")
s3_client = boto3.client('s3')
s3 = boto3.resource('s3')


def lambda_handler(event, context):

   path        =   "/tmp" 
   clone       =   "git clone https://github.com/sirajpathan/test.git" 

# os.system("sshpass -p your_password ssh user_name@your_localhost")
   logger.info(os.getcwd())
   os.chdir(path) 

   os.system(clone) # Cloning
   #os.chdir(os.getcwd())
   folder = os.getcwd() + "/tmp"
   logger.info(os.listdir(os.getcwd()))
   logger.info(os.listdir("/tmp"))

   #shutil.make_archive('Gitpull', 'zip', '/tmp')
   s3_archive_file = 'test.zip'

    # Create zip from /tmp dir without any common prefixes
   shutil.make_archive('test', 'zip', os.getcwd())
   logger.info(os.listdir(os.getcwd()))
   logger.info("Uploading zip to S3://%s/%s" % ('testsiraj1', s3_archive_file))
   #used s3 meta client below
   s3.meta.client.upload_file(os.getcwd() + "/" + s3_archive_file, 'testsiraj1', s3_archive_file)
   ##s3_client.upload_file(os.getcwd(), 'bucketname', s3_archive_file)
   logger.info('Upload Complete')

我得到了只读文件系统:'/var/task/gitpull'only/tmp似乎可以在中写入lambda@harikrishnamurthy现在尝试更新代码。它在lambda tooempty zip文件中工作,将eRename测试文件夹上载到您的repo名称,或者您可以尝试my public repo进行测试