{"id":18524489,"url":"https://github.com/stelligent/mu-ref-dynamodb","last_synced_at":"2025-05-14T19:17:14.684Z","repository":{"id":145835526,"uuid":"120822034","full_name":"stelligent/mu-ref-dynamodb","owner":"stelligent","description":null,"archived":false,"fork":false,"pushed_at":"2020-01-07T20:08:37.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2023-03-23T03:17:02.924Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/stelligent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"publiccode":null,"codemeta":null}},"created_at":"2018-02-08T21:47:54.000Z","updated_at":"2024-06-19T07:58:15.164Z","dependencies_parsed_at":null,"dependency_job_id":"e6996145-0024-41a0-9794-40f621b63179","html_url":"https://github.com/stelligent/mu-ref-dynamodb","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stelligent%2Fmu-ref-dynamodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stelligent%2Fmu-ref-dynamodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stelligent%2Fmu-ref-dynamodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stelligent%2Fmu-ref-dynamodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stelligent","download_url":"https://codeload.github.com/stelligent/mu-ref-dynamodb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239242066,"owners_count":19605946,"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":[],"created_at":"2024-11-06T17:42:01.826Z","updated_at":"2025-02-17T05:42:06.683Z","avatar_url":"https://github.com/stelligent.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mu-ref-dynamodb\n\n## Overview \n\nA simple web service that uses a DynamoDB table. The service is written in go, packaged in a Docker image, and deployed onto ECS with mu: http://getmu.io/\n\nThis is a long running service that was inspired by this one implemented using Lambda: https://alestic.com/2015/07/timercheck-scheduled-events-monitoring/\n\n## Prerequisites\n\n* Configure your AWS credentials. A simple way to do this to install the AWS command line tool, and then run `aws configure`. Instructions for installing the CLI can be found here: https://docs.aws.amazon.com/cli/latest/userguide/installing.html\n\n* Install mu, using these instructions: https://github.com/stelligent/mu/wiki/Installation\n\n## Service API\n\nThe web service has three endpoints:\n\n* / This endpoint just returns OK, and is used as a health check endpoint\n* /{timer-id}/{number-of-seconds} This endpoint creates or resets a timer for a number of seconds\n* /{timer-id}  This endpoint checks the timer, returns 200 with a JSON payload if still running, a 504 if expired\n\nThe typical use case is to detect when some event has *not* occurred. For example, as part of a cron job\nthat should run every every hour, you can add a call to this service to set a timer for 70 minutes.\nThe timer will be reset every hour to run for 70 minutes.\n\nYour monitoring software can poll the timer, and should receive a 200 response. If the cron job has failed to run, \nit will not reset the timer, and the check endpoint will eventually return a 504 error, and the monitoring system can raise an alert.\n\nSee here for an excellent description of the idea: https://alestic.com/2015/07/timercheck-scheduled-events-monitoring/\n\n## Fork this repo\n\nFork this repo. Then edit the mu.yml file, and change the repo name to the be the name of your new repo. A CodePipeline will be created thatis started when changes are committed to this repo, so you want it to have your own repo name, not the stelligent one.\n\n```\nservice:\n  name: timercheck\n  ...\n  pipeline:\n    source:\n      repo: [Put your repo name here]\n  ...\n```\n\nCommit this change and push to GitHub.\n\n```\ngit add mu.yml\ngit commit -m'Use new repo'\ngit push origin master\n```\n\n## Deploy to acceptance environment\n\nYou will need a personal access token from GitHub that CodePipeline will use to access to your repo.\nIf you don't alredy have one of these, you can  go here to set one up: https://github.com/settings/tokens\n\n```\nmu pipeline up -t [GitHub Personal Token]\n```\n\nThis will provision a continuous delivery pipeline that will deploy the service any time something is pushed to the GitHub repo.\nThe pipeline will also be started just after it is created.\n\nThe pipeline will provision an acceptance environment, and deploy the service there. See here for information about the environment mu will created: https://github.com/stelligent/mu/wiki/Environments\n\nThis example uses a mu extension that will also provision a DynamoDB table as part of the environment. See below for a description of the CloudFormation resources created by the mu extension.\n\nYou can monitor the progress of the pipeline by using this command:\n\n```\nmu svc show\n```\n\nOnce the Acceptance stage Deploy action has a status of 'Succeeded', run the following command:\n```\nmu env show acceptance\n```\n\nThis will report the BaseURL that you can use for curl or in a web browser.\n\n## Try the service\n\nCreate a timer with this command:\n\n```\ncurl [URL]/my-first-timer/20\n```\nYou can replace `my-first-timer` with any string you want to use as a timer identifier. Each timer will be saved as a record\nin the DynamoDB table.\n\nUse the same name to check the timer:\n\n```\ncurl [URL]/my-first-timer\n```\n\nThis will return a 200 status code, along with a JSON payload of information about the state of the timer.\nAfter 20 seconds the timer will expire, and a 504 status code will be returned the next time the check endpoint is invoked.\n\n\n## Deploy to production environment\n\nAfter successfully deploying to the acceptance environment, the pipeline will wait for a manual approval. If that is approved, the pipeline will deploy to the production environment. The first time this happens the production environment will be created. You can use the AWS console to approve or reject the deployment.\n\nGo to the CodePipeline console, and follow the link for the `mu-timercheck` pipeline. Click the `Review` button and then you can either approve or reject the revision.\n\n\n### Use the command line for the manual approval step\n\nYou can also use the CLI to approve or reject what was deployed to the acceptance environment. You will need a token from the pipeline state to do this. Use this command:\n```\naws codepipeline get-pipeline-state --name mu-timercheck --query 'stageStates[?stageName==`Production`].actionStates[0][?actionName==`Approve`].latestExecution'\n```\n\nCopy the token from that output and use it for the next step.\n\n### Command line approval\n\nUse the token from the previous step in this command:\n\n```\naws codepipeline put-approval-result --pipeline-name mu-timercheck --stage-name Production --action-name Approve --token [TOKEN] --result status=Approved,summary=Working\n```\n\n\n### Command line rejection\n\nUse the token in this command to cancel the deployment pipeline, and not deploy to production:\n\n```\naws codepipeline put-approval-result --pipeline-name mu-timercheck --stage-name Production --action-name Approve --token [TOKEN] --result status=Rejected,summary=Broke\n```\n\n## Monitor pipeline for production\n\nYou can monitor the progress of the pipeline by using the same command as before:\n\n```\nmu svc show\n```\n\nOnce the Production stage Deploy action has a status of 'Succeeded', run the following command:\n```\nmu env show production\n```\nThis reports the `Base URL` that you can use to interact with the production environment using curl or a web browser.\n\n## Extension to create a DynamoDB table\n\nThe mu.yml file references the dynamodb subdirectory under extensions. The subdirectory contains a custom mu extension. The two files in that subdirectory match names of standard templates that mu uses to provision infrastructure. The CloudFormation resources and parameters in the extension files are merged with the CloudFormation provided by the standard templates. \n(It is also possible to completely replace the default mu CloudFormation, but that's not what we want here. See here for more info about extensions: https://github.com/stelligent/mu/wiki/Custom-CloudFormation#extensions.)\n\nA DynamoDB table is created as part of each environment, so you end up with one in acceptance, and one in production.\n\nThe `service-iam.yml` template adds IAM actions to two different roles in each environment. One role is used by CloudFormation to actually create the table. The other is used by the ECS service, and gives it permission to read and write records in the table.\n\nThe `service-ecs.yml` template is used when creating the environment, and provisions the table.\n\n\n## Cleanup\n\nTo cleanup you can run these commands:\n\n```\nmu environment terminate acceptance\nmu environment terminate production\nmu pipeline terminate\n```\n\nThere are several CloudFormation stacks created by my that are shared by all environments and services: `mu-bucket-codedeploy` and `mu-bucket-codepipeline`. Because these are shared by all environments, you will need to delete these manually using the AWS console or CLI, once you have deleted all services and environments.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstelligent%2Fmu-ref-dynamodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstelligent%2Fmu-ref-dynamodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstelligent%2Fmu-ref-dynamodb/lists"}