• Stars
    star
    1,173
  • Rank 39,852 (Top 0.8 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RSpec tests for your AWS resources.

awspec Gem CI

Logo

RSpec tests for your AWS resources.

Resource Types | Contributing

Installation

Add this line to your application's Gemfile:

gem 'awspec'

And then execute:

$ bundle

Or install it yourself as:

$ gem install awspec

Getting Started

STEP 1. Generate awspec init files

If you're starting on a fresh RSpec project, you can use awspec to generate your init files:

$ awspec init

If you're working on an existing RSpec project, you will need to add the following lines to your spec_helper.rb file:

require 'awspec'
Awsecrets.load(secrets_path: File.expand_path('./secrets.yml', File.dirname(__FILE__)))

STEP 2. Set AWS config

2-1. Use Shared Credentials like AWS CLI

$ aws configure

...

(See http://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-chap-getting-started.html#config-settings-and-precedence)

2-2. Use secrets.yml

$ cat <<EOF > spec/secrets.yml
region: ap-northeast-1
aws_access_key_id: XXXXXXXXXXXXXXXXXXXX
aws_secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
EOF

STEP 3. Write spec/*_spec.rb

require 'spec_helper'

describe ec2('my-ec2-tag-name') do
  it { should be_running }
  its(:instance_id) { should eq 'i-ec12345a' }
  its(:image_id) { should eq 'ami-abc12def' }
  its(:public_ip_address) { should eq '123.0.456.789' }
  it { should have_security_group('my-security-group-name') }
  it { should belong_to_vpc('my-vpc') }
  it { should belong_to_subnet('subnet-1234a567') }
  it { should have_eip('123.0.456.789') }
  it { should be_disabled_api_termination }
end

Using shared_context: region

require 'spec_helper'

describe sqs('my-sqs-queue'), region: 'us-west-2' do
  it { should exist }
  its(:queue_url) { should eq 'https://sqs.us-west-2.amazonaws.com/xxxxxxxxxxxx/my-sqs-queue' }
  its(:queue_arn) { should eq 'arn:aws:sqs:us-west-2:xxxxxxxxxxxx:my-sqs-queue' }
  its(:visibility_timeout) { should eq '30' }
  its(:maximum_message_size) { should eq '256000' }
  its(:message_retention_period) { should eq '86400' }
  its(:delay_seconds) { should eq '0' }
  its(:receive_message_wait_time_seconds) { should eq '10' }
end

Using terraform outputs as identifier

Especially in cases, where resources created by terraform have the same names (e.g. created by VPC module), it is helpful to use terraform outputs as unique identifiers.

output "my_ec2_instance" {
    value = aws_instance.my_instance.id
}
require 'spec_helper'

my_ec2_instance = `terraform output my_ec2_instance`.strip

describe ec2(my_ec2_instance) do
  it { should be_running }
  its(:image_id) { should eq 'ami-abc12def' }
  its(:public_ip_address) { should eq '123.0.456.789' }
  it { should have_security_group('my-security-group-name') }
  it { should belong_to_vpc('my-vpc') }
  it { should belong_to_subnet('subnet-1234a567') }
  it { should have_eip('123.0.456.789') }
  it { should be_disabled_api_termination }
end

STEP 4. Run tests

Add gem "rake" in your Gemfile if you are starting a blank project.

$ bundle exec rake spec

Advanced Tips: Spec generate command

Generate spec from AWS resources already exists.

$ awspec generate ec2 vpc-ab123cde >> spec/ec2_spec.rb

Make sure you have added in your spec file

require 'spec_helper'

Advanced Tips: Use Shared Credentials (~/.aws/config ~/.aws/credentials)

$ awspec generate ec2 vpc-ab123cde --profile mycreds
$ AWS_PROFILE=mycreds bundle exec rake spec

Advanced Tips: Configuring the AWS client retries

The ClientWrap class provides mechanisms for retrying AWS API calls when it receives a RequestLimitExceeded error. ClientWrap implements a backoff algorithm where the client will sleep for successively longer periods of time until the algorithm has calculated a backoff greater than or equal to the backoff_limit, at which point it will give up and re-raise the error. You can see the full implementation in ClientWrap#method_missing.

You can configure this retry and backoff logic in your spec_helper.rb:

require 'awspec'

# These are the defaults, but you can change them.
Awspec.configure do |config|
  config.client_backoff 0.0
  config.client_backoff_limit 30
  config.client_iteration 1
end

Advanced Tips: Setting A Custom Endpoint

Set the endpoint environment variable to tell awspec to use a different endpoint to connect to aws. Common use cases are connecting to aws through a proxy, using a different service with an aws compatible interface, or connecting to a local mock aws environment.

For example, first create a resource on a local aws service using the aws cli:

AWS_SECRET_ACCESS_KEY=dummy AWS_ACCESS_KEY_ID=dummy \
    aws --endpoint-url http://localhost:5000 s3 mb s3://my-bucket

Then you can tell awspec to run the test suite using the same custom endpoint:

endpoint=http://localhost:5000 bundle exec rake spec

Support AWS Resources

Resource Types information here

awspec AWS key/secrets precedence

Dependent on awsecrets.

References

awspec is inspired by Serverspec.

More Repositories

1

tbls

tbls is a CI-Friendly tool for document a database, written in Go.
Go
2,344
star
2

octocov

octocov is a toolkit for collecting code metrics (code coverage, code to test ratio and test execution time).
Go
198
star
3

ndiag

ndiag is a high-level architecture diagramming/documentation tool.
Go
176
star
4

serverless-s3-sync

A plugin to sync local directories and S3 prefixes for Serverless Framework โšก
JavaScript
170
star
5

gh-grep

:octocat: Print lines matching a pattern in repositories using GitHub API
Go
155
star
6

runn

runn is a package/tool for running operations following a scenario.
Go
154
star
7

tcpdp

tcpdp is TCP dump tool with custom dumper and structured logger written in Go.
Go
125
star
8

filt

filt is a interactive/realtime stream filter ( also known as "trial-and-error pipe" ).
Go
74
star
9

evry

Split STDIN stream and execute specified command every N lines/seconds.
Go
64
star
10

colr

๐ŸŽจ colr colors strings, colorfully.
Go
59
star
11

ghput

:octocat: ghput is a CI-friendly tool that puts * on GitHub.
Go
34
star
12

harvest

๐Ÿชฒ Portable log aggregation tool for middle-scale system operation/troubleshooting.
Go
31
star
13

utsusemi

A tool to generate a static website by crawling the original site.
JavaScript
30
star
14

emacs-cake

Minor Mode for editing CakePHP code in Emacs
Emacs Lisp
27
star
15

sakuravps

Shell
27
star
16

emacs-drill-instructor

Enforce key-bind of Emacs. a.k.a ้ฌผ่ปๆ›น.el
Emacs Lisp
27
star
17

frgm

frgm is a meta snippet (fragment) manager.
Go
25
star
18

holiday_jp

[DEPRECATED PROJECT] holiday_jp
Ruby
23
star
19

github-script-ruby

Write workflows scripting the GitHub API in Ruby
Ruby
23
star
20

ghdag

:octocat: ghdag is a tiny workflow engine for GitHub issue and pull request.
Go
23
star
21

fatty

Simple Git repogitory browser plugin for CakePHP
JavaScript
22
star
22

serverless-static-hosting-with-basic-auth

Serverless boilerplate for Static website hosting with Basic authentication
JavaScript
21
star
23

trivy-db-to

trivy-db-to is a tool for migrating/converting vulnerability information from Trivy DB to other datasource.
Go
19
star
24

yalog

Yet Another Logger for CakePHP
PHP
19
star
25

awsdo

awsdo is a tool to do anything using AWS temporary credentials.
Go
19
star
26

execop

ExeCop is a checker that check commands and environment variables before execute command.
Shell
18
star
27

emacs-titanium

Minor Mode for editing Titanium code in Emacs
Emacs Lisp
17
star
28

koma

Koma is an inventory monitoring tool that doesnโ€™t require agent installation on the sever side.
Ruby
17
star
29

awsecrets

AWS credentials loader
Ruby
17
star
30

sheer-heart-attack

๐Ÿ’ฃ A debugging tool that can execute any command on process/host metrics trigger ๐Ÿ’ฅ .
Go
17
star
31

octocov-action

:octocat: GitHub Action for octocov
Shell
17
star
32

certman

CLI tool for AWS Certificate Manager.
Ruby
17
star
33

aws-graph

Draw AWS network graph with Graphviz.
Ruby
16
star
34

sconb

Ssh CONfig Buckup tool.
Ruby
16
star
35

docker-alpine-pandoc-ja

Pandoc for Japanese based on Alpine Linux
Dockerfile
15
star
36

model_info

CakePHP DB Schema/Model Info Plugin
PHP
13
star
37

fake

Fixture generator plugin for cAKEphp.
PHP
13
star
38

viewpath

Viewpath: View file path display plugin for CakePHP
PHP
12
star
39

CacooViewer

Simple `Cacoo' diagrams viewer.
JavaScript
12
star
40

Yacsv

Yet another CSV utility plugin for CakePHP
PHP
12
star
41

grouped_process_exporter

Exporter for grouped process
Go
11
star
42

emacs-serverspec

Serverspec minor mode
Emacs Lisp
11
star
43

dirmap

๐Ÿ“ dirmap is a tool for generating a directory map.
Go
11
star
44

metr

metr provides an easy way to use host/process metrics for shell script/monitoring tool.
Go
11
star
45

gh-setup

:octocat: Setup asset of Github releases.
Go
10
star
46

connected

๐Ÿ”Œ Watch your MacBook connection โšก
Go
10
star
47

glyph

Icon as Code
Go
10
star
48

controller_prefix

`Controller name prefix' custom route plugin for CakePHP
PHP
10
star
49

emacs-cake2

Minor Mode for editing CakePHP2 code in Emacs
Emacs Lisp
10
star
50

sshc

sshc.NewClient() returns *ssh.Client using ssh_config(5)
Go
10
star
51

tbls-ask

tbls-ask is an external subcommand of tbls for asking OpenAI using the datasource.
Go
10
star
52

tokyotyrant_php

Yet Another "Tokyo Tyrant" PHP Interface
PHP
9
star
53

pr-bullet

pr-bullet is a tool for copying pull request to multiple repositories.
Go
9
star
54

recipe

recipe - CakePHP CLI Package Installer -
PHP
9
star
55

emacs-historyf

file history library like browser
Emacs Lisp
9
star
56

escape

Auto escaping plugin for CakePHP
PHP
8
star
57

yak

Yet Another Ktai plugin for CakePHP
PHP
8
star
58

ebk

ebk is a tiny tool for ebook
Go
8
star
59

emacs-ac-cake2

Emacs Lisp
8
star
60

pear_local

PEAR Local install plugin for CakePHP
PHP
8
star
61

stopw

A stopwatch library in Go for nested time measurement.
Go
8
star
62

emacs-ac-cake

Emacs Lisp
8
star
63

duration

duration.Parse() parses a formatted string and returns the time.Duration value it represents.
Go
8
star
64

auto-complete-exuberant-ctags

Exuberant ctags auto-complete.el source
Emacs Lisp
8
star
65

has_no

Simple binding model practice plugin for CakePHP.
PHP
7
star
66

mackerel-plugin-prometheus-exporter

๐ŸŸ Mackerel plugin for scraping Prometheus exporter metrics. ๐Ÿ”ฅ
Go
7
star
67

awsrm

Simple AWS Resource "READONLY" Mapper for awspec.
Ruby
7
star
68

jquery-cakephp-debugkit

Add JavaScript valiables panel to 'CakePHP DebugKit'
JavaScript
7
star
69

gh-star-history

:octocat: Show star history of repositories. โญ
Go
7
star
70

tbls-meta

tbls-meta is an external subcommand of tbls for applying metadata managed by tbls to the datasource.
Go
6
star
71

tmpfk

Temporary foreign key add/drop tool for using ERD generator for "Keyless entry (SQL Antipatterns)" schema.
Ruby
6
star
72

DebugMemo

DebugMemo: Memo tool for development / CakePHP plugin
PHP
6
star
73

anything-exuberant-ctags

Exuberant ctags anything.el interface
Emacs Lisp
6
star
74

brewfile-desc

brewfile-desc add descriptions of formulae to Brewfile.
Go
6
star
75

po

CakePHP .po File Edit Plugin
PHP
6
star
76

ghfs

:octocat: Go io/fs implementation for GitHub remote repository
Go
5
star
77

Exception

Exception plugin for CakePHP
PHP
5
star
78

backlog-favicon-changer

Chrome Extension to change favicon for multiple Backlog projects.
JavaScript
5
star
79

emacs-yarm

Yet Another Ruby on Rails Minor Mode for Emacs
Emacs Lisp
5
star
80

calendar

Calendar plugin for CakePHP
PHP
5
star
81

anything-replace-string

replace-string() and query-string() `anything.el' interface
Emacs Lisp
5
star
82

calver

calver is a package/tool provides the ability to work with Calendar Versioning in Go.
Go
5
star
83

ssh_config_to_vuls_config

sc2vc: ssh_config to vuls config TOML format
Ruby
5
star
84

phpenv-nginx-ansible-vagrant

Ruby
5
star
85

typd

ใŠๅ‰ใฏไปŠใพใงๅ…ฅๅŠ›ใ—ใŸใƒ•ใ‚ฉใƒผใƒ ใฎๅ€คใ‚’่ฆšใˆใฆใ„ใ‚‹ใฎใ‹?
JavaScript
5
star
86

Setting

Database driven setting plugin for CakePHP.
PHP
5
star
87

backslack

Bridge between Backlog and Slack
JavaScript
5
star
88

anything-hatena-bookmark

Hatena::Bookmark anything.el interface
Emacs Lisp
5
star
89

Yasd

Yet Another SoftDeletable Behavior for CakePHP
PHP
5
star
90

tbls-build

tbls-build is an external subcommand of tbls for customizing config file of tbls using other tbls.yml or schema.json.
Go
5
star
91

curlreq

curlreq creates *http.Request from curl command.
Go
4
star
92

Sample-Calendar-Application

Sample Application for the CakePHP Calendar Plugin
PHP
4
star
93

repin

repin is a tool to replace strings between keyword pair.
Go
4
star
94

lrep

lrep = l/re/p = line regular expression parser
Go
4
star
95

webroot_view

CakePHP library for use elements and helpers under app/webroot/
PHP
4
star
96

Back

Sessoin base `history back' plugin for CakePHP
PHP
4
star
97

keyp

keyp is a tool to keep public keys up to date.
Go
4
star
98

property-enum

Property based enum plugin for CakePHP 3
PHP
4
star
99

slkm

slkm is github.com/slack-go/slack wrapper package for posting message.
Go
4
star
100

emacs-key-cast

Key Storke Casting Minor Mode for Emacs
4
star