aws / aws-sdk-ruby

The official AWS SDK for Ruby.
https://aws.amazon.com/sdk-for-ruby/
Apache License 2.0
3.53k stars 1.21k forks source link

Aws::CloudHSMV2::Client#delete_hsm -> NoMethodError/undefined method `delete_hsm' for #<Aws::CloudHSMV2::Types::Hsm:0x000000146a80d8> #1674

Closed eniskonuk closed 6 years ago

eniskonuk commented 6 years ago

Please fill out the sections below to help us address your issue

Issue description

Even though the delete_hsm API endpoint is defined in docs and in the api definition for CloudHSMV2, the delete_hsm method does not seem to get auto-generated in any of the current gem version. Tested on 2.10.84, 2.10.100 and 3.x.x.

Gem name ('aws-sdk', 'aws-sdk-resources' or service gems like 'aws-sdk-s3') and its version

aws-sdk 2.10.100

Version of Ruby, OS environment

2.4.1/Ubuntu 16.04LTS

Code snippets / steps to reproduce

hsm = Aws::CloudHSMV2::Client.new(
  :http_wire_trace => false,
  :region => region, :credentials => @aws_cred, :logger => @aws_logger
)
begin
  resp_c = hsm.describe_clusters
  resp_c.clusters.each do |cc|
    cc.hsms.each do |hsm|
      hsm.delete_hsm(cluster_id: hsm.cluster_id, hsm_id: hsm.hsm_id)
    end
    hsm.delete_cluster(cluster_id: cc.cluster_id)
  end
rescue => e
end
awood45 commented 6 years ago

The problem is your code example has defined hsm twice, in different contexts. When you're calling it in the block, it's now a type shape, not the client. Here is code which will work:

hsm_client = Aws::CloudHSMV2::Client.new(
  :http_wire_trace => false,
  :region => region, :credentials => @aws_cred, :logger => @aws_logger
)
begin
  resp_c = hsm_client.describe_clusters
  resp_c.clusters.each do |cc|
    cc.hsms.each do |hsm|
      hsm_client.delete_hsm(cluster_id: hsm.cluster_id, hsm_id: hsm.hsm_id)
    end
    hsm_client.delete_cluster(cluster_id: cc.cluster_id)
  end
rescue => e
end
eniskonuk commented 6 years ago

You're absolutely right @awood45. I feel like a dufus.