RSpec 会测试您的 AWS 资源。
将以下行添加到您应用程序的 Gemfile 中:
gem 'awspec'然后执行: $ bundle 或者自己安装如下: $ gem install awspec
如果您正在新建一个 RSpec 项目,可以使用 awspec 生成初始化文件:
$ awspec init
如果您正在处理现有的 RSpec 项目,则需要在 spec_helper.rb 文件中添加以下行:
require 'awspec'
Awsecrets.load(secrets_path: File.expand_path('./secrets.yml', File.dirname(__FILE__)))$ aws configure
...$ cat spec/secrets.yml
region: ap-northeast-1
aws_access_key_id: XXXXXXXXXXXXXXXXXXXX
aws_secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
EOFrequire '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 }
endrequire 'spec_helper'
describe sqs('my-sqs-queue'), region: 'us-west-2'
它 { 应该存在 }
its(:queue_url) { 应该等于 'https://sqs.us-west-2.amazonaws.com/xxxxxxxxxxxx/my-sqs-queue'' }
its(:queue_arn) { 应该等于 'arn:AWS:sqs:us-west-2:xxxxxxxxxxxx:my-sqs-queue' }
its(:visibility_timeout) { 应为 '30' }
its(:maximum_message_size) { 应为 '256000' }
its(:message_retention_period) { 说明暂无开放 Issues,或尚未同步最近议题。