{"id":24503653,"url":"https://github.com/plus3it/cfn-update-scheduler","last_synced_at":"2025-08-14T04:24:08.668Z","repository":{"id":70263169,"uuid":"121815017","full_name":"plus3it/cfn-update-scheduler","owner":"plus3it","description":"Lambda function to automate CloudFormation stack updates","archived":false,"fork":false,"pushed_at":"2018-07-16T17:28:11.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-17T23:43:03.707Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plus3it.png","metadata":{"files":{"readme":"README.md","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,"publiccode":null,"codemeta":null}},"created_at":"2018-02-17T00:23:29.000Z","updated_at":"2019-01-31T21:26:44.000Z","dependencies_parsed_at":"2023-03-17T12:45:51.086Z","dependency_job_id":null,"html_url":"https://github.com/plus3it/cfn-update-scheduler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/plus3it/cfn-update-scheduler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plus3it%2Fcfn-update-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plus3it%2Fcfn-update-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plus3it%2Fcfn-update-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plus3it%2Fcfn-update-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plus3it","download_url":"https://codeload.github.com/plus3it/cfn-update-scheduler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plus3it%2Fcfn-update-scheduler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270360672,"owners_count":24570760,"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","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-01-21T23:17:57.426Z","updated_at":"2025-08-14T04:24:08.632Z","avatar_url":"https://github.com/plus3it.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CFN Update Scheduler\n\nA [Serverless framework](https://serverless.com/learn/) deployable Lambda function pair that generates a CloudWatch rule that will automatically perform stack updates when called as a custom resource within CloudFormation.\n\n## Getting Started\n\nThese instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.\n\n### Prerequisites\n\n1. Command line access to an AWS account with administrative access.\n\n2. Ensure your environment has been configured in accordance with the [AWS installation instructions for the serverless framework](https://serverless.com/framework/docs/providers/aws/guide/installation/).\n\n3. Install the [serverless-pseudo-parameters](https://www.npmjs.com/package/serverless-pseudo-parameters) plugin\n\n```\nnpm install serverless-pseudo-parameters\n```\n\n### Installing\n\n1. Download this repository\n\n```\ngit clone git://github.com/userhas404d/cfn_update_scheduler.git\n```\n\n2. Using the Serverless framework, deploy the project to your AWS environment\n\n```\nsls deploy\n```\n\n## Running the tests\n\nExplain how to run the automated tests for this system\n\n### Break down into end to end tests\n\nExplain what these tests test and why\n\n```\nGive an example\n```\n\n### And coding style tests\n\nExplain what these tests test and why\n\n```\nGive an example\n```\n\n## Deployment\n\n1. Deploy the included CloudFormation template or add a custom resource to your own template as outlined below.\n\n*Note:*\n*The included CloudFormation template utilizes the following ADDITIONAL custom resource: [`AmiIdLookup` custom resource](https://github.com/userhas404d/cfn-look-up-ami-ids)*\n\n2. During stack deployment include your stack's desired update interval as a cron expression or `rate(value unit)` for the `UpdateSchedule` parameter. See the following AWS documentation for further details: [Schedule Expressions for Rules](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html)\n\n3. Confirm the CloudWatch rule has been created for your stack by navigating to the CloudWatch \u003e Rules section of your AWS account's web console.\n\n#### CloudFormation template required Parameters:\nA toggle is utilized to force CloudFormation to re-evaluate a resource during the stack update.\n\n```\n\"ForceUpdateToggle\" :\n{\n    \"Description\" : \"A/B toggle that forces a change to a LaunchConfig property, triggering the stack Update Policy\",\n    \"Type\" : \"String\",\n    \"Default\" : \"A\",\n    \"AllowedValues\" :\n       [\n          \"A\",\n          \"B\"\n       ]\n},\n\"UpdateSchedule\" :\n{\n  \"Description\" : \"Time interval between auto stack updates\",\n  \"Type\" : \"String\",\n  \"Default\" : \"5 minutes\"\n}\n```\n#### CloudFormation template required Resources:\nThe included [example template](https://github.com/userhas404d/cfn_update_scheduler/blob/master/Lambda-cfn-auto-update.template) utilizes this toggle to update the value of the `AdditionalInfo` property of an EC2 instance. This in turn forces the [`AmiIdLookup` custom resource](https://github.com/userhas404d/cfn-look-up-ami-ids) to always return the latest AMI Id on stack update.\n```\n\"Resources\" : {\n    \"SampleInstance\": {\n      \"Type\": \"AWS::EC2::Instance\",\n      \"Properties\": {\n        \"InstanceType\"   : { \"Ref\" : \"InstanceType\" },\n        \"ImageId\": { \"Fn::GetAtt\" : [ \"AmiIdLookup\", \"Id\" ] },\n        \"AdditionalInfo\" : { \"Ref\" : \"ForceUpdateToggle\"}\n      }\n    },\n    \"AmiIdLookup\" :\n    {\n          \"Type\" : \"Custom::AmiIdLookup\",\n          \"Properties\" :\n          {\n              \"ServiceToken\" :\n              { \"Fn::Join\" : [ \":\", [\n                  \"arn:aws:lambda\",\n                  { \"Ref\" : \"AWS::Region\" },\n                  { \"Ref\" : \"AWS::AccountId\" },\n                  \"function:cfn-look-up-amis-ids-dev-cfn-look-up-amis-ids\"\n              ]]},\n              \"Region\" : { \"Ref\" : \"AWS::Region\" },\n              \"AmiNameSearchString\" : { \"Ref\" : \"AmiNameSearchString\" },\n              \"TemplateAmiID\" : { \"Ref\" : \"AmiId\" },\n              \"AutoUpdateAmi\" : { \"Ref\" : \"AutoUpdateAmi\" }\n          }\n    }\n```\nAnd finally the custom resource that references the `cfn_update_broker` Lambda function.\n```\n\"AutoUpdateStack\" :\n{\n      \"Type\" : \"Custom::AutoUpdateStack\",\n      \"Properties\" :\n      {\n          \"ServiceToken\" :\n          { \"Fn::Join\" : [ \":\", [\n              \"arn:aws:lambda\",\n              { \"Ref\" : \"AWS::Region\" },\n              { \"Ref\" : \"AWS::AccountId\" },\n              \"function:cfn-update-scheduler-dev-cfn_auto_update_broker\"\n          ]]},\n          \"StackName\" : { \"Ref\" : \"AWS::StackName\" },\n          \"UpdateSchedule\": { \"Fn::Join\" : [\n            \"\", [\"rate(\",{ \"Ref\" : \"UpdateSchedule\" }, \")\"]\n            ]},\n          \"ToggleParameter\" : \"ForceUpdateToggle\",\n          \"ToggleValues\" : [\"A\",\"B\"]\n      }\n}\n```\n## Functionality Overview\n\nWhen this project's serverless package is deployed two lambda functions will be created.\n\n### `cfn_auto_update_broker`\n\nThis function is running with a least privilege IAM role (`cfn-update-scheduler-dev-us-east-1-lambdaRole`) and operates as the listener to the CloudWatch custom resource.\n\nIt operates as follows:\n\n* On receiving a CREATE event :\n\n    - Create CloudWatch rule and include the stack specific `ForceUpdateToggle` and `ToggleValues` in the rule's `Constant`\n\n    - Add stack to the CloudWatch rule target\n\n    - Add required permissions to the `cwe_update_target` function to allow the event to trigger the update.\n\n\n* On receiving a UPDATE event:\n\n  - update the CloudWatch rule schedule and `Constant`\n\n* On receiving a DELETE event:\n\n  - delete the CloudWatch rule.\n\n### `cwe_update_target`\n\nThis function is invoked by the scheduled Cloudwatch rules. On receiving the rule's event it does the following:\n\n* Assumes an administrative role (`StackUpdateRole`) to perform stack updates.\n\n  - It assumes this role for a default of 3600 seconds.\n\n\n  *Note: `StackUpdateRole` does NOT exercise principles of least privilege. This will be addressed in a follow on update.*\n\n  * Swaps the value of the `ForceUpdateToggle` from A to B or B to A accordingly.\n\n    - These values are customizable but currently the list must include two separate values.\n\n\n  * Updates the target stack utilizing the assumed role and the updated `ForceUpdateToggle` values.\n\n## Built With\n\n* [Serverless](https://serverless.com/learn/) - The deployment method used\n* [Boto 3](http://boto3.readthedocs.io/en/latest/) - programatic AWS resource manipulation\n* [cfnresponse.py](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html) - module to send responses to AWS resources\n\n## License\n\nThis project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details\n\n## To Do\n- unit testing with moto https://github.com/spulec/moto\n- document testing..\n- move resource declarations out of globals and into function parameters\n- better error handling\n- send notifications to a sns topic on update or failure.\n- improve readme\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplus3it%2Fcfn-update-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplus3it%2Fcfn-update-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplus3it%2Fcfn-update-scheduler/lists"}