{"id":20657746,"url":"https://github.com/boltops-tools/cfn_response","last_synced_at":"2026-04-22T06:02:37.839Z","repository":{"id":55194701,"uuid":"253943464","full_name":"boltops-tools/cfn_response","owner":"boltops-tools","description":"CfnResponse makes it easier to build and send the CloudFormation Custom Resource response","archived":false,"fork":false,"pushed_at":"2021-01-06T06:26:56.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-13T17:16:48.972Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/boltops-tools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-08T00:21:52.000Z","updated_at":"2022-02-02T02:10:29.000Z","dependencies_parsed_at":"2022-08-14T15:41:54.939Z","dependency_job_id":null,"html_url":"https://github.com/boltops-tools/cfn_response","commit_stats":null,"previous_names":["tongueroo/cfn_response"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/boltops-tools/cfn_response","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boltops-tools%2Fcfn_response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boltops-tools%2Fcfn_response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boltops-tools%2Fcfn_response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boltops-tools%2Fcfn_response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boltops-tools","download_url":"https://codeload.github.com/boltops-tools/cfn_response/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boltops-tools%2Fcfn_response/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32061251,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T11:35:06.609Z","status":"ssl_error","status_checked_at":"2026-04-20T11:34:48.899Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2024-11-16T18:22:47.784Z","updated_at":"2026-04-22T06:02:37.801Z","avatar_url":"https://github.com/boltops-tools.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CfnResponse\n\n[![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)\n\nCfnResponse helps with writing [Custom CloudFormation resources](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html). It builds the response to send back to CloudFormation from the Lambda function.\n\n## Usage\n\nThe block form with the `response` method will ensure a SUCCESS or FAILED status is sent to CloudFormation regardless. If there's an Exception in the code, FAILED status is automatically sent. Otherwise an implicit SUCCESS status is sent.\n\nThis prevents us from waiting for over an hour for the stack operation to timeout and rollback. A `sleep 10` is also called at the end to provide enough time for the Lambda function to send logs to CloudWatch.\n\n```ruby\nrequire \"cfn_response\"\nrequire \"json\"\n\ndef lambda_handler(event:, context:)\n  puts \"event: #{JSON.pretty_generate(event)}\"\n  cfn = CfnResponse.new(event, context)\n\n  # will call cfn.fail on Exceptions so CloudFormation can continue\n  cfn.response do\n    case event['RequestType']\n    when \"Create\", \"Update\"\n      # create or update logic\n    when \"Delete\"\n      # delete logic\n    end\n    # Note: cfn.success doesnt need to be called because it is called implicitly at the end\n  end\nend\n```\n\nIf you always want to return a success, here's the simpliest form:\n\n```ruby\nrequire \"cfn_response\"\nrequire \"json\"\n\ndef lambda_handler(event:, context:)\n  puts \"event: #{JSON.pretty_generate(event)}\"\n  cfn = CfnResponse.new(event, context)\n  cfn.response\nend\n```\n\nReminder, `cfn.success` or `cfn.fail` is not called explicitly, a `cfn.success` is automatically called.\n\n### Calling success or fail explicitly\n\nYou can also call `cfn.success` or `cfn.fail explicitly`, doing so gives you the ability to pass custom `Data`.\n\n```ruby\nrequire \"cfn_response\"\nrequire \"json\"\n\ndef lambda_handler(event:, context:)\n  puts \"event: #{JSON.pretty_generate(event)}\"\n  cfn = CfnResponse.new(event, context)\n\n  # will call cfn.fail on Exceptions so CloudFormation can continue\n  cfn.response do\n    case event['RequestType']\n    when \"Create\", \"Update\"\n      # create or update logic\n      data = {a: 1, b: 2}\n      cfn.success(Data: data)\n      # or\n      # cfn.failed\n    when \"Delete\"\n      # delete logic\n      cfn.success # optional\n    end\n  end\nend\n```\n\n### Non-block form\n\nYou can also call `success` and `failed` methods without wrapping the in a `response` block.  Just remember to handle Exceptions. Example:\n\n```ruby\nrequire \"cfn_response\"\nrequire \"json\"\n\ndef lambda_handler(event:, context:)\n  puts \"event: #{JSON.pretty_generate(event)}\"\n  cfn = CfnResponse.new(event, context)\n\n  data = {a: 1, b: 2}\n  cfn.success(Data: data)\n  # or\n  # cfn.failed\n\n  sleep 10 # a little time for logs to be sent to CloudWatch\n# Rescue all exceptions and send FAIL to CloudFormation so we don't have to\n# wait for over an hour for the stack operation to timeout and rollback.\nrescue Exception =\u003e e\n  puts e.message\n  puts e.backtrace\n  sleep 10 # a little time for logs to be sent to CloudWatch\n  cfn.failed\nend\n```\n\n### Custom Resource Provider Response Fields\n\nUltimately, CloudFormation expects a JSON body to be sent to it with these possible fields: Status, Reason, PhysicalResourceId, StackId, RequestId, LogicalResourceId, NoEcho, Data. Docs: [Custom Resource Response Objects](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html).\n\nThe `success` and `failed` methods accept a Hash which is simply merged down to the final JSON body that is sent to CloudFormation. Most of the fields are prefilled conveniently by this library.  You may want to pass some values.  Example:\n\n```ruby\ncfn = CfnResponse.new(event, context)\ncfn.success(Data: {a: 1, b: 2}, NoEcho: true)\n```\n\n### PhysicalResourceId\n\nThe default PhysicalResourceId is `PhysicalResourceId`. If your logic calls for a new physical resource and you want to tell CloudFormation to replace the resource. Then you can provide a value with the symbol `:new_id` and the library will add a counter value to end of the current physical id.\n\n```ruby\ncfn = CfnResponse.new(event, context)\ncfn.success(PhysicalResourceId: :new_id)\n# PhysicalResourceId =\u003e PhysicalResourceId1 =\u003e PhysicalResourceId2 =\u003e etc\n```\n\nOr you replace it with your own unique physical resource id value of course.\n\n```ruby\ncfn = CfnResponse.new(event, context)\ncfn.success(PhysicalResourceId: \"MyId\")\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'cfn_response'\n```\n\nAnd then execute:\n\n    bundle install\n\nOr install it yourself as:\n\n    gem install cfn_response\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/tongueroo/cfn_response\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboltops-tools%2Fcfn_response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboltops-tools%2Fcfn_response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboltops-tools%2Fcfn_response/lists"}