|
254 | 254 |
|
255 | 255 | LOG = logging.getLogger(__name__) |
256 | 256 |
|
| 257 | +CAPACITY_PROVIDER_ARN_NAME = "arn:aws[a-zA-Z-]*:lambda:(eusc-)?[a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\\d{1}:\\d{12}:capacity-provider:[a-zA-Z0-9-_]+" |
257 | 258 | LAMBDA_DEFAULT_TIMEOUT = 3 |
258 | 259 | LAMBDA_DEFAULT_MEMORY_SIZE = 128 |
259 | 260 |
|
@@ -852,6 +853,30 @@ def _validate_layers(self, new_layers: list[str], region: str, account_id: str): |
852 | 853 | ) |
853 | 854 | visited_layers[layer_arn] = layer_version_arn |
854 | 855 |
|
| 856 | + def _validate_capacity_provider( |
| 857 | + self, capacity_provider_config: CapacityProviderConfig, context: RequestContext |
| 858 | + ): |
| 859 | + if not capacity_provider_config.get("LambdaManagedInstancesCapacityProviderConfig"): |
| 860 | + raise ValidationException( |
| 861 | + "1 validation error detected: Value null at 'capacityProviderConfig.lambdaManagedInstancesCapacityProviderConfig' failed to satisfy constraint: Member must not be null" |
| 862 | + ) |
| 863 | + |
| 864 | + capacity_provider_arn = capacity_provider_config.get( |
| 865 | + "LambdaManagedInstancesCapacityProviderConfig", {} |
| 866 | + ).get("CapacityProviderArn") |
| 867 | + if not capacity_provider_arn: |
| 868 | + raise ValidationException( |
| 869 | + "1 validation error detected: Value null at 'capacityProviderConfig.lambdaManagedInstancesCapacityProviderConfig.capacityProviderArn' failed to satisfy constraint: Member must not be null" |
| 870 | + ) |
| 871 | + |
| 872 | + if not re.match(CAPACITY_PROVIDER_ARN_NAME, capacity_provider_arn): |
| 873 | + raise ValidationException( |
| 874 | + f"1 validation error detected: Value '{capacity_provider_arn}' at 'capacityProviderConfig.lambdaManagedInstancesCapacityProviderConfig.capacityProviderArn' failed to satisfy constraint: Member must satisfy regular expression pattern: {CAPACITY_PROVIDER_ARN_NAME}" |
| 875 | + ) |
| 876 | + |
| 877 | + capacity_provider_name = capacity_provider_arn.split(":")[-1] |
| 878 | + self.get_capacity_provider(context, capacity_provider_name) |
| 879 | + |
855 | 880 | @staticmethod |
856 | 881 | def map_layers(new_layers: list[str]) -> list[LayerVersion]: |
857 | 882 | layers = [] |
@@ -1028,11 +1053,12 @@ def create_function( |
1028 | 1053 | # Runtime management controls are not available when providing a custom image |
1029 | 1054 | runtime_version_config = None |
1030 | 1055 |
|
1031 | | - # TODO: validations and figure out in which order |
1032 | 1056 | capacity_provider_config = None |
1033 | 1057 | memory_size = request.get("MemorySize", LAMBDA_DEFAULT_MEMORY_SIZE) |
1034 | 1058 | if "CapacityProviderConfig" in request: |
1035 | 1059 | capacity_provider_config = request["CapacityProviderConfig"] |
| 1060 | + self._validate_capacity_provider(capacity_provider_config, context) |
| 1061 | + |
1036 | 1062 | default_config = CapacityProviderConfig( |
1037 | 1063 | LambdaManagedInstancesCapacityProviderConfig=LambdaManagedInstancesCapacityProviderConfig( |
1038 | 1064 | ExecutionEnvironmentMemoryGiBPerVCpu=2.0, |
|
0 commit comments