diff --git a/docs/source/compute_config/aws_batch.md b/docs/source/compute_config/aws_batch.md index 0116652cc..d03642b99 100644 --- a/docs/source/compute_config/aws_batch.md +++ b/docs/source/compute_config/aws_batch.md @@ -130,7 +130,7 @@ In summary, you can use one of the following settings: | aws_batch | runtime_memory | 1024 | no | Runtime memory assigned to each task container. | | aws_batch | runtime_cpu | 0.5 | no | Number of vCPUs assigned to each task container. It can be different from `worker_processes`. | | aws_batch | worker_processes | 1 | no | Number of parallel Lithops processes in a worker. This is used to parallelize function activations within the worker. | -| aws_batch | service_role | `None` | no | Service role for AWS Batch. Leave empty to use a service-linked execution role. More info [here](https://docs.aws.amazon.com/batch/latest/userguide/using-service-linked-roles.html) | +| aws_batch | service_role | | no | Service role for AWS Batch. Leave empty to use a service-linked execution role. More info [here](https://docs.aws.amazon.com/batch/latest/userguide/using-service-linked-roles.html) | | aws_batch | env_max_cpus | 10 | no | Maximum total CPUs of the compute environment | | aws_batch | env_type | FARGATE_SPOT | no | Compute environment type, one of: `["EC2", "SPOT", "FARGATE", "FARGATE_SPOT"]` | diff --git a/docs/source/compute_config/aws_ec2.md b/docs/source/compute_config/aws_ec2.md index 1ae362156..dc1a5b61b 100644 --- a/docs/source/compute_config/aws_ec2.md +++ b/docs/source/compute_config/aws_ec2.md @@ -120,7 +120,7 @@ Alternatively, you can set the `reuse` mode to keep running the started worker V 4. Go back to **IAM** and navigate to **Roles** tab. Click **Create role**. -5. Choose **EC2** on the use case list. Click **Next: Permissions**. Select the policy created before (`lithops-policy`). Click **Next: Tags** and **Next: Review**. Type a role name, for example `lithops-ec2-execution-role`. Click on **Create Role**. +5. Choose **EC2** on the use case list. Click **Next: Permissions**. Select the policy created before (`lithops-policy`). Click **Next: Tags** and **Next: Review**. Type a role name, for example `ec2LithopsInstanceRole`. Click on **Create Role**. ### AWS Credential setup @@ -138,7 +138,7 @@ In summary, you can use one of the following settings: aws_ec2: region : - iam_role: + instance_role: exec_mode: reuse ``` @@ -153,7 +153,7 @@ In summary, you can use one of the following settings: region: aws_ec2: - iam_role: + instance_role: exec_mode: reuse ``` @@ -172,7 +172,7 @@ In summary, you can use one of the following settings: |Group|Key|Default|Mandatory|Additional info| |---|---|---|---|---| |aws_ec2 | region | |no | Region name, for example: `eu-west-1`. Lithops will use the `region` set under the `aws` section if it is not set here | -|aws_ec2 | iam_role | | yes | IAM EC2 role name. You can find it in the [IAM Console page](https://console.aws.amazon.com/iamv2/home#/roles). Create a new EC2 role if it does not exist. Do not use the full ARN here; only the role name is required| +|aws_ec2 | instance_role | | yes | EC2 Instance role name created in the configuration section above. Do not use the full ARN here; only the role name is required. For example: `ec2LithopsInstanceRole`| |aws_ec2 | vpc_id | | no | VPC id. You can find all the available VPCs in the [VPC Console page](https://console.aws.amazon.com/vpc/v2/home#vpcs:) | |aws_ec2 | subnet_id | | no | Subnet id. You can find all the available Subnets in the [VPC Console page](https://console.aws.amazon.com/vpc/v2/home#subnets:) | |aws_ec2 | security_group_id | | no | Security group ID. You can find the available security groups in the [VPC console page](https://console.aws.amazon.com/vpc/v2/home#SecurityGroups:). The security group must have ports 22 and 8080 open | diff --git a/lithops/serverless/backends/aws_batch/aws_batch.py b/lithops/serverless/backends/aws_batch/aws_batch.py index 2ed406055..d0ca74b49 100644 --- a/lithops/serverless/backends/aws_batch/aws_batch.py +++ b/lithops/serverless/backends/aws_batch/aws_batch.py @@ -144,19 +144,12 @@ def _create_compute_env(self): compute_resources_spec['minvCpus'] = 0 compute_resources_spec['instanceTypes'] = ['optimal'] - if 'service_role' in self.aws_batch_config: - res = self.batch_client.create_compute_environment( - computeEnvironmentName=self._compute_env_name, - type='MANAGED', - computeResources=compute_resources_spec, - serviceRole=self.aws_batch_config['service_role'] - ) - else: - res = self.batch_client.create_compute_environment( - computeEnvironmentName=self._compute_env_name, - type='MANAGED', - computeResources=compute_resources_spec, - ) + res = self.batch_client.create_compute_environment( + computeEnvironmentName=self._compute_env_name, + type='MANAGED', + computeResources=compute_resources_spec, + serviceRole=self.aws_batch_config.get('service_role', "") + ) if res['ResponseMetadata']['HTTPStatusCode'] != 200: raise Exception(res) diff --git a/lithops/serverless/backends/aws_batch/config.py b/lithops/serverless/backends/aws_batch/config.py index 4b939fb3d..0346a2b1a 100644 --- a/lithops/serverless/backends/aws_batch/config.py +++ b/lithops/serverless/backends/aws_batch/config.py @@ -106,7 +106,7 @@ def load_config(config_data): # container_vcpus is deprectaded. To be removed in a future release if 'container_vcpus' in config_data['aws_batch']: - config_data['aws_batch']['runtime_cpu'] = config_data['aws_batch']['container_vcpus'] + config_data['aws_batch']['runtime_cpu'] = config_data['aws_batch'].pop('container_vcpus') if config_data['aws_batch']['env_type'] in {'FARGATE', 'FARGATE_SPOT'}: runtime_memory = config_data['aws_batch']['runtime_memory'] diff --git a/lithops/standalone/backends/aws_ec2/aws_ec2.py b/lithops/standalone/backends/aws_ec2/aws_ec2.py index bf3f1c01e..d58daa28b 100644 --- a/lithops/standalone/backends/aws_ec2/aws_ec2.py +++ b/lithops/standalone/backends/aws_ec2/aws_ec2.py @@ -587,7 +587,7 @@ def init(self): 'master_id': self.vpc_key, 'vpc_name': self.vpc_name, 'vpc_id': self.config['vpc_id'], - 'iam_role': self.config['iam_role'], + 'instance_role': self.config['instance_role'], 'target_ami': self.config['target_ami'], 'ssh_key_name': self.config['ssh_key_name'], 'ssh_key_filename': self.config['ssh_key_filename'], @@ -1174,7 +1174,7 @@ def _create_instance(self, user_data=None): "ImageId": self.config['target_ami'], "InstanceType": self.instance_type, "EbsOptimized": False, - "IamInstanceProfile": {'Name': self.config['iam_role']}, + "IamInstanceProfile": {'Name': self.config['instance_role']}, "Monitoring": {'Enabled': False}, 'KeyName': self.config['ssh_key_name'] } diff --git a/lithops/standalone/backends/aws_ec2/config.py b/lithops/standalone/backends/aws_ec2/config.py index 203b3c0b0..fec660c24 100644 --- a/lithops/standalone/backends/aws_ec2/config.py +++ b/lithops/standalone/backends/aws_ec2/config.py @@ -32,7 +32,7 @@ } REQ_PARAMS_1 = ('instance_id',) -REQ_PARAMS_2 = ('iam_role',) +REQ_PARAMS_2 = ('instance_role',) def load_config(config_data): @@ -66,6 +66,10 @@ def load_config(config_data): else: params_to_check = REQ_PARAMS_2 + # iam_role is deprectaded. To be removed in a future release + if 'iam_role' in config_data['aws_ec2']: + config_data['aws_ec2']['instance_role'] = config_data['aws_ec2'].pop('iam_role') + for param in params_to_check: if param not in config_data['aws_ec2']: msg = f"'{param}' is mandatory in the 'aws_ec2' section of the configuration"