def _build(config, rebuild_deps=False): package = datetime.utcnow().strftime("lambda_package.%Y%m%d_%H%M%S.zip") ignore = ['\.slam\/venv\/.*$', '\.pyc$'] if os.environ.get('VIRTUAL_ENV'): # make sure the currently active virtualenv is not included in the pkg venv = os.path.relpath(os.environ['VIRTUAL_ENV'], os.getcwd()) if not venv.startswith('.'): ignore.append(venv.replace('/', '\/') + '\/.*$') # create .slam directory if it doesn't exist yet if not os.path.exists('.slam'): os.mkdir('.slam') _generate_lambda_handler(config) # create or update virtualenv if rebuild_deps: if os.path.exists('.slam/venv'): shutil.rmtree('.slam/venv') if not os.path.exists('.slam/venv'): _run_command('virtualenv .slam/venv') _run_command('.slam/venv/bin/pip install -r ' + config['requirements']) # build lambda package build_package('.', config['requirements'], virtualenv='.slam/venv', extra_files=['.slam/handler.py'], ignore=ignore, zipfile_name=package) # cleanup lambda uploader's temp directory if os.path.exists('.lambda_uploader_temp'): shutil.rmtree('.lambda_uploader_temp') return package
def _execute(args): '''Main execution function''' venv = None if args.no_virtualenv: venv = False elif args.virtualenv: venv = args.virtualenv pkg_pth = args.function_dir or args.package_name requirements = args.requirements or [] LOG.info("Building package " + args.artifact_pth) pkg = build_package(pkg_pth, requirements, virtualenv=venv, ignore=args.ignore, extra_files=args.extra_files, zipfile_name=args.artifact_pth, pyexec=args.runtime) if not args.no_clean: pkg.clean_workspace() if args.s3_key_prefix: obj_name = args.s3_key_prefix + path.basename(pkg.zip_file) else: obj_name = path.basename(pkg.zipfile) if args.subparser_name == 'upload': aws_session = boto3.session.Session(region_name=args.region, profile_name=args.profile_name) LOG.info("Uploading artifact to " + args.bucket_name) s3_client = aws_session.client('s3') transfer = boto3.s3.transfer.S3Transfer(s3_client) transfer.upload_file(pkg.zip_file, args.bucket_name, obj_name) # Output Lambda Package Name print(obj_name)
def _execute(args): pth = path.abspath(args.function_dir) cfg = config.Config(pth, args.config, role=args.role) _print('Building Package') pkg = package.build_package(pth, cfg.requirements, args.virtualenv) if not args.no_clean: pkg.clean_workspace() if not args.no_upload: # Set publish if flagged to do so if args.publish: cfg.set_publish() create_alias = False # Set alias if the arg is passed if args.alias is not None: cfg.set_alias(args.alias, args.alias_description) create_alias = True _print('Uploading Package') upldr = uploader.PackageUploader(cfg, args.profile) upldr.upload(pkg) # If the alias was set create it if create_alias: upldr.alias() pkg.clean_zipfile() _print('Fin')
def build_lambda_package(self): LOG.warning("Building Lambda package ...") pkg = package.build_package(self.lambda_path, None, extra_files=self.extra_files) pkg.clean_workspace() return pkg
def _execute(args): pth = path.abspath(args.function_dir) cfg = config.Config(pth, args.config, role=args.role, variables=args.variables) if args.s3_bucket: cfg.set_s3(args.s3_bucket, args.s3_key) if args.no_virtualenv: # specified flag to omit entirely venv = False elif args.virtualenv: # specified a custom virtualenv venv = args.virtualenv else: # build and include virtualenv, the default venv = None if args.no_build: pkg = package.create_package(pth) else: _print('Building Package') requirements = cfg.requirements if args.requirements: requirements = path.abspath(args.requirements) extra_files = cfg.extra_files if args.extra_files: extra_files = args.extra_files pkg = package.build_package(pth, requirements, venv, cfg.ignore, extra_files) if not args.no_clean: pkg.clean_workspace() if not args.no_upload: # Set publish if flagged to do so if args.publish: cfg.set_publish() create_alias = False # Set alias if the arg is passed if args.alias is not None: cfg.set_alias(args.alias, args.alias_description) create_alias = True _print('Uploading Package') upldr = uploader.PackageUploader(cfg, args.profile) upldr.upload(pkg) # If the alias was set create it if create_alias: upldr.alias() if cfg.subscription: _print('Creating subscription') subscribers.create_subscriptions(cfg, args.profile) pkg.clean_zipfile() _print('Fin')
def _execute(args): pth = path.abspath(args.function_dir) cfg = config.Config(pth, args.config, role=args.role, variables=args.variables) if args.s3_bucket: cfg.set_s3(args.s3_bucket, args.s3_key) if args.no_virtualenv: # specified flag to omit entirely venv = False elif args.virtualenv: # specified a custom virtualenv venv = args.virtualenv else: # build and include virtualenv, the default venv = None if args.no_build: pkg = package.create_package(pth) else: _print('Building Package') requirements = cfg.requirements if args.requirements: requirements = path.abspath(args.requirements) extra_files = cfg.extra_files if args.extra_files: extra_files = args.extra_files pkg = package.build_package(pth, requirements, venv, cfg.ignore, extra_files) if not args.no_clean: pkg.clean_workspace() if not args.no_upload: # Set publish if flagged to do so if args.publish: cfg.set_publish() create_alias = False # Set alias if the arg is passed if args.alias is not None: cfg.set_alias(args.alias, args.alias_description) create_alias = True _print('Uploading Package') upldr = uploader.PackageUploader(cfg, args.profile) upldr.upload(pkg) # If the alias was set create it if create_alias: upldr.alias() pkg.clean_zipfile() _print('Fin')
def _execute(args): pth = path.abspath(args.function_dir) cfg = config.Config(pth) _print('Building Package') pkg = package.build_package(pth, cfg.requirements) if not args.no_clean: pkg.clean_workspace() if not args.no_upload: _print('Uploading Package') uploader.upload_package(pkg, cfg) pkg.clean_zipfile() _print('Fin')
def _execute(args): pth = path.abspath(args.function_dir) cfg = config.Config(pth, args.config, role=args.role) if args.no_virtualenv: # specified flag to omit entirely venv = False elif args.virtualenv: # specified a custom virtualenv venv = args.virtualenv else: # build and include virtualenv, the default venv = None _print('Building Package') pkg = package.build_package(pth, cfg.requirements, venv, cfg.ignore) if not args.no_clean: pkg.clean_workspace() if not args.no_upload: # Set publish if flagged to do so if args.publish: cfg.set_publish() create_alias = False # Set alias if the arg is passed if args.alias is not None: cfg.set_alias(args.alias, args.alias_description) create_alias = True _print('Uploading Package') upldr = uploader.PackageUploader(cfg, args.profile) upldr.upload(pkg) # If the alias was set create it if create_alias: upldr.alias() pkg.clean_zipfile() _print('Fin')