I'm attempting to create a zip file to upload to AWS Lambda, but I can't seem to create the zip file correctly.
What I need to create is a zip file that only contains the files themselves, using this code:
def zipdir(path, ziph):
for root, dirs, files in os.walk(path):
for file in files:
filepath = os.path.join(root, file)
if file == 'config.json' or file.startswith('.'):
pass
else:
info = zipfile.ZipInfo(filename=file)
ziph.write(filename=filepath, arcname='./' + file)
I successfully create the archive, but I always get the file contents in a directory with the same name as the archive.
If I compress:
code.js
And then decompress, testing.zip I'll get:
testing/code.js
How do I prevent the directory from being created?
Not familiar with python, but I use Makefile instead
create:
[ -e "pkg.zip" ] && rm pkg.zip &2> /dev/null
zip -r pkg.zip . \
--exclude=test* \
--exclude=node_modules/aws-sdk*
aws lambda create-function \
--function-name $(func) \
--zip-file fileb://pkg.zip \
--role arn:aws:iam::YOUR_ACCOUNT_ID:role/gff_lambda \
--handler index.handler \
--timeout 30 \
--runtime nodejs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.