github.com/sharovik/devbot@v1.0.1-0.20240308094637-4a0387c40516/documentation/terraform-aws-setup.md (about) 1 # AWS setup 2 If you have AWS account you might need to install the DevBot there. 3 4 ## Prerequisites 5 - install the aws cli into your system. So you will able to use the AWS cli commands. 6 - create `~/.aws/credentials` file and put there your AWS credentials OR export AWS credentials in memory 7 - install the docker to your system 8 - after aws cli were installed and credentials are exported into memory, please run ecr login command 9 - install terraform to your system 10 - make sure you run `make build` before the project build 11 ``` 12 aws ecr get-login-password --region us-east-1 13 ``` 14 15 ## 1 Step - Push your image to AWS ECR repository 16 ### 1. Create the repository 17 First you need to create ECR repository where you will store your image 18 ``` 19 aws ecr create-repository --repository-name devbot 20 ``` 21 To make sure the repository exists, run next command: 22 ``` 23 aws ecr describe-repositories 24 ``` 25 You should see your repository there. Example: 26 ``` 27 { 28 "repositories": [ 29 { 30 "repositoryArn": "arn:aws:ecr:us-east-1:aws_account_id:repository/devbot", 31 "registryId": "aws_account_id", 32 "repositoryName": "devbot", 33 "repositoryUri": "aws_account_id.dkr.ecr.us-east-1.amazonaws.com/devbot", 34 "createdAt": 1590751353.0 35 } 36 ] 37 } 38 ``` 39 40 ### 2. Build and tag the image 41 First you need build the **devbot** image using `docker` 42 ``` 43 docker build -t devbot:latest . 44 ``` 45 After image build was finished, please tag your image 46 ``` 47 docker tag TAG_ID aws_account_id.dkr.ecr.us-east-1.amazonaws.com/devbot:latest 48 ``` 49 `TAG_ID` you can find using this command 50 ``` 51 docker images | grep "devbot" 52 ``` 53 As the result you will see something like this 54 ``` 55 devbot latest c4dac21ebc43(this is TAG_ID) 20 minutes ago 740MB 56 ``` 57 58 ### 2. Push your image into ECR repository 59 Run next command to push your image into ECR repository: 60 ``` 61 docker push aws_account_id.dkr.ecr.us-east-1.amazonaws.com/devbot 62 ``` 63 64 ## 2 Step - Create terraform ECS task container definition file 65 You for doing this you can manually run the next command `make tf-container-definition`. This step will create the `local.container_definition.tf` file if it doesn't exists inside of `terraform` directory. 66 In that file you can add or update existing variables for your devbot ECS instance. 67 68 ## 3 Step - Apply changes 69 Before start, you need first to initialize the terraform inside of the terraform folder. 70 71 So, please go to the `terraform` folder and run `terraform init` command there. If everything is good, then you can run next command `terraform apply`, which will applies the changes in AWS. Please, make sure you check changes before applying! 72 If something goes wrong, you always can run `terraform destroy` to destroy all created instances.