{"id":24461061,"url":"https://github.com/oxide-byte/todo-fargate","last_synced_at":"2025-05-06T00:08:05.103Z","repository":{"id":230447663,"uuid":"769694832","full_name":"oxide-byte/todo-fargate","owner":"oxide-byte","description":"An AWS Todo Application running a Rust Leptos Application with Server Side Rendering on a Fargate instance. Containing a DynamoDB and Network configuration.","archived":false,"fork":false,"pushed_at":"2024-04-05T18:43:37.000Z","size":2041,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-06T00:07:57.958Z","etag":null,"topics":["aws","dynamodb","fargate","leptos","rust","sam","ssr","vpc"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oxide-byte.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-09T19:45:59.000Z","updated_at":"2024-09-14T10:24:39.000Z","dependencies_parsed_at":"2024-03-29T20:23:50.178Z","dependency_job_id":"d69b475d-834c-4549-ae70-b1b02030ab53","html_url":"https://github.com/oxide-byte/todo-fargate","commit_stats":null,"previous_names":["oxide-byte/todo-fargate"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxide-byte%2Ftodo-fargate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxide-byte%2Ftodo-fargate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxide-byte%2Ftodo-fargate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxide-byte%2Ftodo-fargate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oxide-byte","download_url":"https://codeload.github.com/oxide-byte/todo-fargate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252596414,"owners_count":21773845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","dynamodb","fargate","leptos","rust","sam","ssr","vpc"],"created_at":"2025-01-21T04:17:13.478Z","updated_at":"2025-05-06T00:08:05.084Z","avatar_url":"https://github.com/oxide-byte.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Todo Fargate\n\n== Warning\n\nThis project is an experimental project, to share the experiences made with Fargate, and to share as during the development I found no project containing all these elements.\n\n*ATTENTION:* This project generates costs when deployed on AWS, as Fargate is not part of the Free Tier. During my tests\nit was under 1$, even when done a lot of deployments, I cleaned and removed my ECS Tasks and reduced the runtimes as most as possible:\n\nimage::.readme-resources/billing.png[]\n\nSo keep your Budget Plan on eye, configure it, and *REMOVE* your resources after you're finished !!!!\n\nThis Project contains 2 parts:\n\n* Rust / Leptos Server Side Rendering\n* AWS / Fargate / DynamoDB Deployment\n\n== RUST / LEPTOS\n\nFor the part of Leptos, the cargo file is generated by https://book.leptos.dev/ssr/21_cargo_leptos.html\nwith the commands:\n\n```bash\ncargo install cargo-leptos\n```\n\n```bash\ncargo leptos new --git leptos-rs/start-axum\n```\n\nAfter initialisation, I could take most of my development from my project: https://github.com/oxide-byte/todo-serverless\n\nThe main modification points had been:\n\n* The starting of the Axum Server in Main\n* The implementation of the Server Side Rendering in the Service (#[server(GetTodos, \"/api\")]...)\n* And a better understanding of Rust Features and #[cfg(feature = \"ssr\")]\n\nIn the docker-compose.yaml you find a local DynamoDB with an UI, to develop and test locally.\n\nYou can start the Server locally with (run.sh)\n```bash\nexport local=true\ncargo leptos watch\n```\n\nThe Dockerfile builds the image to transfer to AWS ECR and executed as Fargate Task later. The Docker image could be on the runner part lighter, but for simplicity I kept the Build proposed from Leptos: https://book.leptos.dev/deployment/ssr.html\n\n## AWS\n\nThe Deployment of the application is build on CloudFormation SAM, containing nearly all the elements to make the application runnable.\n\nThe SAM Template create:\n\n* A CloudWatch Log Group\n* A new public network with Subnets, VPC, Internet Gateway, Routing Table, Security Group\n* A Fargate ECS Cluster, Task Definition and Service\n* A DynamoDB Database\n\nBefore applying the SAM Template, you need first in your Region an Elastic Container Registry, where the Docker image of your application is uploaded. For this use the AWS Web Interface and create a new Registry:\n\nimage::.readme-resources/ecr.png[]\n\nYou need to replace in Makefile the XXXXXXXXXXXXXXXX from the variable AWS_ID with your own ID (12 Digits)\n\nimage::.readme-resources/account_id.png[AccountId,200,100]\n\n```\n# Image and repository variables\nIMAGE_NAME := todo-fargate\nAWS_ID := XXXXXXXXXXXXXXXX\nREGION_ID := eu-west-1\n```\n\nSame for the SAM template.yaml\n\n```\nParameters:\n  ImageRepository:\n    Type: String\n    Default: XXXXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/todo-fargate:latest\n```\n\nAs you see, the project is linked to the region: eu-west-1 (Ireland), if you work with an other region, consider to search and replace the value in the different resources of the project.\n\nIn the Makefile, we have the different steps to build the Docker Image and Cloud Formation:\n\n1. Build a Docker image locally on your PC/Laptop with the step: build\n\n2. Tag the image and push it to the ECR with the step: push\n\n3. Build the SAM Template for Cloud Formation, deploy it, and start the ECS Fargate Task (Attention running costs) with the step: aws-sam\n\n```\nCloudFormation stack changeset\n-------------------------------------------------------------------------------------------------\nOperation                LogicalResourceId        ResourceType             Replacement\n-------------------------------------------------------------------------------------------------\n+ Add                    CloudWatchLogsGroup      AWS::Logs::LogGroup      N/A\n+ Add                    SubnetA                  AWS::EC2::Subnet         N/A\n+ Add                    SubnetB                  AWS::EC2::Subnet         N/A\n+ Add                    TodoCluster              AWS::ECS::Cluster        N/A\n+ Add                    TodoDB                   AWS::DynamoDB::Table     N/A\n+ Add                    TodoDefinition           AWS::ECS::TaskDefiniti   N/A\n+ Add                    TodoExecutionRole        AWS::IAM::Role           N/A\n+ Add                    TodoInternetGatewayAtt   AWS::EC2::VPCGatewayAt   N/A\n+ Add                    TodoInternetGatewayRou   AWS::EC2::Route          N/A\n+ Add                    TodoInternetGateway      AWS::EC2::InternetGate   N/A\n+ Add                    TodoRouteTableAssociat   AWS::EC2::SubnetRouteT   N/A\n+ Add                    TodoRouteTableAssociat   AWS::EC2::SubnetRouteT   N/A\n+ Add                    TodoRouteTable           AWS::EC2::RouteTable     N/A\n+ Add                    TodoSecurityGroupEgres   AWS::EC2::SecurityGrou   N/A\n+ Add                    TodoSecurityGroupIngre   AWS::EC2::SecurityGrou   N/A\n+ Add                    TodoSecurityGroupIngre   AWS::EC2::SecurityGrou   N/A\n+ Add                    TodoSecurityGroupIngre   AWS::EC2::SecurityGrou   N/A\n+ Add                    TodoSecurityGroup        AWS::EC2::SecurityGrou   N/A\n+ Add                    TodoService              AWS::ECS::Service        N/A\n+ Add                    TodoVpc                  AWS::EC2::VPC            N/A\n-------------------------------------------------------------------------------------------------\n```\n\nimage::.readme-resources/cloud-formation.png[]\n\nThe public IP can be found inside the Elastic Container Service:\n\nimage::.readme-resources/ecs.png[]\n\nfollowing the task:\n\nimage::.readme-resources/ecs-task.png[]\n\nand looking on the Network Configuration:\n\nimage::.readme-resources/ecs-task-ip.png[]\n\nWhen finished, clean the AWS deployment in using the Step : clean from Makefile or command:\n\n```\nsam delete\n```\n\nand validate after that all resources have been removed:\n\nimage::.readme-resources/validate_delete.png[]\n\n== Headache\n\nA point that had made some headache and needed a longer research was an error in the logs of Rust Task:\n\n```\nTask stopped at: 2024-03-14T21:29:24.899Z\nResourceInitializationError: unable to pull secrets or registry auth: execution resource retrieval failed: unable to retrieve ecr registry auth: service call has been retried 3 time(s): RequestError: send request failed caused by: Post \"https://api.ecr.eu-west-1.amazonaws.com/\": dial tcp 63.34.61.49:443: i/o timeout. Please check your task network configuration.\n```\n\nIn my case it was this part of missing definition on [TodoDefinition]\n\n```\nExecutionRoleArn: !GetAtt TodoExecutionRole.Arn\nTaskRoleArn: !GetAtt TodoExecutionRole.Arn\n```\n\nAn other point on the network, this must be well defined, and the TaskService need access to the Internet Gateway, or it will fail and restart:\n\nimage::.readme-resources/network.png[]\n\nAlways distinct between the default resources and the created when analysing and debugging for problems.\n\n== Disclaimer\n\nThis GitHub project is experimental application for education purpose. It's important to acknowledge that cloud services could generate costs based on usage, configuration, and external factors.\n\nBy accessing and utilizing this project, you agree that:\n\n    Cost Management Responsibility: You are responsible for monitoring and managing the costs associated with deploying and running this application in your own cloud environment. This includes understanding the pricing structure of the cloud service provider and making informed decisions to optimize costs.\n\n    Usage and Deployment: You acknowledge that the usage and deployment of this application may result in charges from the cloud service provider. It's essential to review and comprehend the pricing details provided by the cloud service provider before deploying the application.\n\n    No Liability: The creators and contributors of this project are not liable for any costs incurred as a result of deploying, running, or modifying this application. This includes, but is not limited to, charges accrued from cloud services, unexpected usage spikes, or misconfigurations.\n\n    Best Practices and Recommendations: We strongly recommend implementing cost management best practices, such as setting up budget alerts, utilizing cost-effective resources, and regularly reviewing usage reports to avoid unexpected expenses.\n\n    Continuous Monitoring: It's your responsibility to continuously monitor the usage and costs associated with running this application. Periodic reviews of cloud billing statements and resource utilization are essential to ensure cost-effectiveness.\n\n    Feedback and Contributions: We welcome feedback and contributions to enhance the efficiency and cost-effectiveness of this project. However, any changes made to optimize costs should be thoroughly tested to ensure they do not compromise the functionality or security of the application.\n\nBy proceeding with the usage of this project, you acknowledge that you have read, understood, and agreed to the terms outlined in this disclaimer. If you do not agree with these terms, refrain from accessing or utilizing this project.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxide-byte%2Ftodo-fargate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxide-byte%2Ftodo-fargate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxide-byte%2Ftodo-fargate/lists"}