Skip to content

Commit

Permalink
Adding kinesis_stream resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Marchesi committed Sep 18, 2015
1 parent bd3f27f commit ce01eab
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -571,6 +571,28 @@ Attribute parameters are:
in the CloudFormation user guide.


## aws_kinesis_stream

Use this resource to create and delete Kinesis streams. Note that this resource
cannot be used to modify the shard count as shard splitting is a somewhat
complex operation (for example, CloudFormation replaces streams upon update).

```
aws_kinesis 'example-stream' do
action :create
starting_shard_count 1
end
```

Actions:

* `create`: Creates the stream. No effect if the stream already exists.
* `delete`: Deletes the stream.

Use `starting_shard_count` to control the amount of shards the stream starts
with.


## aws_iam_user

Use this resource to manage IAM users.
Expand Down
13 changes: 13 additions & 0 deletions libraries/kinesis.rb
@@ -0,0 +1,13 @@
require File.join(File.dirname(__FILE__), 'ec2')

module Opscode
module Aws
module Kinesis
include Opscode::Aws::Ec2

def kinesis
@kinesis ||= create_aws_interface(::Aws::Kinesis::Client)
end
end
end
end
36 changes: 36 additions & 0 deletions providers/kinesis_stream.rb
@@ -0,0 +1,36 @@
include Opscode::Aws::Kinesis

def whyrun_supported?
true
end

# does_stream_exist - logic for checking if the stream exists
def stream_exists?
resp = kinesis.describe_stream(stream_name: new_resource.stream_name)
if resp.length > 0
true
else
false
end
rescue ::Aws::Kinesis::Errors::ResourceNotFoundException
false
end

action :create do
unless stream_exists?
converge_by("create Kinesis stream #{new_resource.stream_name}") do
kinesis.create_stream(
stream_name: new_resource.stream_name,
shard_count: new_resource.starting_shard_count
)
end
end
end

action :delete do
if stream_exists?
converge_by("delete Kinesis stream #{new_resource.stream_name}") do
kinesis.delete_stream(stream_name: new_resource.stream_name)
end
end
end
10 changes: 10 additions & 0 deletions resources/kinesis_stream.rb
@@ -0,0 +1,10 @@
default_action :create
actions :create, :delete

attribute :stream_name, kind_of: String, name_attribute: true
attribute :starting_shard_count, kind_of: Integer, required: true
# AWS common attributes
attribute :region, kind_of: String, default: nil
attribute :aws_access_key, kind_of: String, default: nil
attribute :aws_secret_access_key, kind_of: String, default: nil
attribute :aws_session_token, kind_of: String, default: nil
4 changes: 4 additions & 0 deletions test/fixtures/cookbooks/aws_test/recipes/kinesis_stream.rb
@@ -0,0 +1,4 @@
aws_kinesis_stream 'kitchen-test-stream' do
action :create
starting_shard_count 2
end

0 comments on commit ce01eab

Please sign in to comment.