Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tongueroo/cfnresponse
CloudFormation send_response helper for custom resource
https://github.com/tongueroo/cfnresponse
Last synced: about 1 month ago
JSON representation
CloudFormation send_response helper for custom resource
- Host: GitHub
- URL: https://github.com/tongueroo/cfnresponse
- Owner: tongueroo
- License: mit
- Created: 2019-02-10T05:43:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-10T02:06:48.000Z (over 4 years ago)
- Last Synced: 2024-10-14T22:16:43.815Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Cfnresponse
NOTE: This library has been replaced by [tongueroo/cfn_response](https://github.com/tongueroo/cfn_response). It's interface is much improved.
[![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
Cfnresponse helps with writing [Custom CloudFormation resources](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html). The main method is `send_response`, which builds the response that is sent back to CloudFormation service from the Lambda function.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'cfnresponse'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install cfnresponse
## Example Usage
```ruby
require "cfnresponse"
include Cfnresponsedef lambda_handler(event:, context:)
puts("Received event: " + json_pretty(event))case event['RequestType']
when "Create"
# create logic
send_response(event, context, "SUCCESS")
when "Update"
# update logic
send_response(event, context, "SUCCESS")
when "Delete"
# delete logic
send_response(event, context, "SUCCESS")
endsleep 10 # a little time for logs to be sent to CloudWatch
# We rescue all exceptions and send a message to CloudFormation so we don't have to
# wait for over an hour for the stack operation to timeout and rollback.
rescue Exception => e
puts e.message
puts e.backtrace
sleep 10 # a little time for logs to be sent to CloudWatch
send_response(event, context, "FAILED")
end
```* [Cfnresponse code](lib/cfnresponse.rb)