Skip to content

Commit

Permalink
Merge pull request #1360 from JosepSampe/lithops-dev
Browse files Browse the repository at this point in the history
[AWS] Fix missing ecsTaskJobRole
  • Loading branch information
JosepSampe authored May 27, 2024
2 parents d726a69 + 6533a58 commit 5a4336c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- [Worker] Fixed potential issue that can appear during 'func_obj' loading from cache
- [Monitor] Fixed potential 'keyerror' exceptions
- [Swift] Fixed OpenStack Swift parameters and authentication by adding domain information

- [AWS Batch] Fixed missing ecsTaskJobRole

## [v3.3.0]

Expand Down
32 changes: 32 additions & 0 deletions docs/source/compute_config/aws_batch.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ python3 -m pip install lithops[aws]
3. Navigate to **IAM > Roles** to create the ECS Instance Role. AWS provides a default role named `ecsInstanceRole`, which can be used instead. If you want to create another role or it is missing, create a new role attached to `EC2`, and add the following policy:
- `AmazonEC2ContainerServiceforEC2Role`

4. Navigate to **IAM > Policies**. Click on **Create policy**. If you already created this policy for the AWS Lambda or AWS EC2 backend, jump to step 7.

5. Select **JSON** tab and paste the following JSON policy:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*",
"lambda:*",
"ec2:*",
"ecr:*",
"sts:GetCallerIdentity",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
```

6. Click **Next: Tags** and **Next: Review**. Fill the policy name field (you can name it `lithops-policy` or similar) and create the policy.

7. Go back to **IAM** and navigate to **Roles** tab. Click **Create role**.

8. Choose **Elastic Container Service** on the use case list and then click on **Elastic Container Service Task**. Click **Next: Permissions**. Select the policy created before (`lithops-policy`). Click **Next: Tags** and **Next: Review**. Type a role name, for example `ecsTaskJobRole`. Click on **Create Role**.

## AWS Credential setup

Lithops loads AWS credentials as specified in the [boto3 configuration guide](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html).
Expand Down Expand Up @@ -90,6 +121,7 @@ In summary, you can use one of the following settings:
|Group|Key|Default|Mandatory|Additional info|
|---|---|---|---|---|
| aws_batch | execution_role | | yes | ARN of the execution role used to execute AWS Batch tasks on ECS for Fargate environments |
| aws_batch | job_role | | yes | ARN of the job role used to execute AWS Batch tasks on ECS for Fargate environments|
| aws_batch | instance_role | | yes | ARN of the execution role used to execute AWS Batch tasks on ECS for EC2 environments |
| aws_batch | security_groups | | yes | List of Security groups to attach for ECS task containers. By default, you can use a security group that accepts all outbound traffic but blocks all inbound traffic. |
| aws_batch | subnets | | yes | List of subnets from a VPC where to deploy the ECS task containers. Note that if you are using a **private subnet**, you can set `assign_public_ip` to `false` but make sure containers can reach other AWS services like ECR, Secrets service, etc., by, for example, using a NAT gateway. If you are using a **public subnet** you must set `assign_public_up` to `true` |
Expand Down
37 changes: 36 additions & 1 deletion docs/source/compute_config/aws_ec2.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,41 @@ In summary, you can use one of the following settings:
In the `create` mode, Lithops will automatically create new worker VM instances in runtime, scale Lithops job against generated VMs, and automatically delete the VMs when the job is completed.
Alternatively, you can set the `reuse` mode to keep running the started worker VMs, and reuse them for further executions. In the `reuse` mode, Lithops checks all the available worker VMs and start new workers only if necessary.


### Configuration

1. Navigate to **IAM > Policies**. Click on **Create policy**. If you already created this policy for the AWS Lambda or AWS Batch backend, jump to step 4.

2. Select **JSON** tab and paste the following JSON policy:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*",
"lambda:*",
"ec2:*",
"ecr:*",
"sts:GetCallerIdentity",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
```

3. Click **Next: Tags** and **Next: Review**. Fill the policy name field (you can name it `lithops-policy` or similar) and create the policy.

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**.


### AWS Credential setup

Lithops loads AWS credentials as specified in the [boto3 configuration guide](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html).
Expand Down Expand Up @@ -137,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|
|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 | 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 |
Expand Down
2 changes: 1 addition & 1 deletion docs/source/compute_config/aws_lambda.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ python3 -m pip install lithops[aws]

5. Go back to **IAM** and navigate to **Roles** tab. Click **Create role**.

6. Choose **Lambda** on the use case list and click **Next: Permissions**. Select the policy created before (`lithops-policy`). Click **Next: Tags** and **Next: Review**. Type a role name, for example `lithops-execution-role`. Click on *Create Role*.
6. Choose **Lambda** on the use case list and click **Next: Permissions**. Select the policy created before (`lithops-policy`). Click **Next: Tags** and **Next: Review**. Type a role name, for example `lithops-lambda-execution-role`. Click on *Create Role*.

## AWS Credential setup

Expand Down
1 change: 1 addition & 0 deletions lithops/serverless/backends/aws_batch/aws_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def _create_job_def(self, runtime_name, runtime_memory):
container_properties = {
'image': image_name,
'executionRoleArn': self.aws_batch_config['execution_role'],
'jobRoleArn': self.aws_batch_config['job_role'],
'resourceRequirements': [
{
'type': 'VCPU',
Expand Down

0 comments on commit 5a4336c

Please sign in to comment.