Load the local zappa_settings file. An existing boto session can be supplied, though this is likely for testing purposes. Returns the loaded Zappa object.
(self, settings_file=None, session=None)
| 2579 | return |
| 2580 | |
| 2581 | def load_settings(self, settings_file=None, session=None): |
| 2582 | """ |
| 2583 | Load the local zappa_settings file. |
| 2584 | An existing boto session can be supplied, though this is likely for testing purposes. |
| 2585 | Returns the loaded Zappa object. |
| 2586 | """ |
| 2587 | |
| 2588 | # Load up settings (from file or environment) |
| 2589 | self.load_settings_file(settings_file) |
| 2590 | |
| 2591 | # Make sure that this stage is our settings |
| 2592 | if self.api_stage not in self.zappa_settings.keys(): |
| 2593 | raise ClickException("Please define stage '{0!s}' in your Zappa settings.".format(self.api_stage)) |
| 2594 | |
| 2595 | # We need a working title for this project. Use one if supplied, else cwd dirname. |
| 2596 | if "project_name" in self.stage_config: # pragma: no cover |
| 2597 | # If the name is invalid, this will throw an exception with message up stack |
| 2598 | self.project_name = validate_name(self.stage_config["project_name"]) |
| 2599 | else: |
| 2600 | self.project_name = self.get_project_name() |
| 2601 | |
| 2602 | # The name of the actual AWS Lambda function, ex, 'helloworld-dev' |
| 2603 | # Assume that we already have have validated the name beforehand. |
| 2604 | # Related: https://github.com/Miserlou/Zappa/pull/664 |
| 2605 | # https://github.com/Miserlou/Zappa/issues/678 |
| 2606 | # And various others from Slack. |
| 2607 | self.lambda_name = slugify.slugify(self.project_name + "-" + self.api_stage) |
| 2608 | |
| 2609 | # Load stage-specific settings |
| 2610 | self.s3_bucket_name = self.stage_config.get( |
| 2611 | "s3_bucket", |
| 2612 | "zappa-" + "".join(random.choice(string.ascii_lowercase + string.digits) for _ in range(9)), |
| 2613 | ) |
| 2614 | self.vpc_config = self.stage_config.get("vpc_config", {}) |
| 2615 | |
| 2616 | # Load and validate EFS configuration |
| 2617 | raw_efs_config = self.stage_config.get("efs_config", None) |
| 2618 | self.efs_config = [] |
| 2619 | |
| 2620 | if raw_efs_config: |
| 2621 | if not self.vpc_config: |
| 2622 | raise ClickException("efs_config requires vpc_config to be set") |
| 2623 | |
| 2624 | # Normalize configuration to list format |
| 2625 | if raw_efs_config is True: |
| 2626 | # Minimal config: efs_config: true -> single mount at default path |
| 2627 | self.efs_config = [{"LocalMountPath": DEFAULT_EFS_MOUNT_POINT}] |
| 2628 | elif isinstance(raw_efs_config, dict): |
| 2629 | # Single dict config -> wrap in list |
| 2630 | self.efs_config = [raw_efs_config] |
| 2631 | elif isinstance(raw_efs_config, list): |
| 2632 | self.efs_config = raw_efs_config |
| 2633 | |
| 2634 | # Validate each EFS entry |
| 2635 | mount_paths = set() |
| 2636 | for idx, efs in enumerate(self.efs_config): |
| 2637 | # Default LocalMountPath |
| 2638 | if "LocalMountPath" not in efs: |