From fe649d3e5dbc7016108102ea485eabf5620409cc Mon Sep 17 00:00:00 2001 From: Chris Selzo Date: Wed, 15 Nov 2023 15:33:54 -0800 Subject: [PATCH] Include deprecated AMIs when creating light stemcell After a max of 2 years, AWS "deprecates" public AMIs, which means that they do not show up in `DescribeImages` API calls. (You can still use them as long as you know their ID) This leads to an error like the following when using > 2-year-old (and therefore deprecated) stemcell AMIs: ``` bosh us https://bosh.io/d/stemcells/bosh-aws-xen-hvm-ubuntu-xenial-go_agent?v=621.125 Using environment '10.0.16.10' as client 'ops_manager' Task 10 Task 10 | 23:24:10 | Update stemcell: Downloading remote stemcell (00:00:01) Task 10 | 23:24:11 | Update stemcell: Verifying remote stemcell (00:00:00) Task 10 | 23:24:11 | Update stemcell: Extracting stemcell archive (00:00:00) Task 10 | 23:24:11 | Update stemcell: Verifying stemcell manifest (00:00:00) Task 10 | 23:24:16 | Update stemcell: Checking if this stemcell already exists (cpi: 543ec2c1aa4f72578fa3) (00:00:00) Task 10 | 23:24:16 | Update stemcell: Uploading stemcell bosh-aws-xen-hvm-ubuntu-xenial-go_agent/621.125 to the cloud (cpi: 543ec2c1aa4f72578fa3) (00:00:02) L Error: CPI error 'Bosh::Clouds::CloudError' with message 'Stemcell does not contain an AMI in region us-west-1' in 'create_stemcell' CPI method (CPI request ID: 'cpi-457127') Task 10 | 23:24:18 | Error: CPI error 'Bosh::Clouds::CloudError' with message 'Stemcell does not contain an AMI in region us-west-1' in 'create_stemcell' CPI method (CPI request ID: 'cpi-457127') Task 10 Started Wed Nov 15 23:24:10 UTC 2023 Task 10 Finished Wed Nov 15 23:24:18 UTC 2023 Task 10 Duration 00:00:08 Task 10 error Uploading remote stemcell 'https://bosh.io/d/stemcells/bosh-aws-xen-hvm-ubuntu-xenial-go_agent?v=621.125': Expected task '10' to succeed but state is 'error' Exit code 1 ``` Even though the CPI knows the exact AMI ID of the stemcell image, it makes a `DescribeImages` call when creating a light stemcell. The AWS SDK allows for an `include_deprecated` option when making the call, and adding that option solves the issue. Reference: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ami-deprecate.html [#186468123] --- src/bosh_aws_cpi/lib/cloud/aws/cloud_v1.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bosh_aws_cpi/lib/cloud/aws/cloud_v1.rb b/src/bosh_aws_cpi/lib/cloud/aws/cloud_v1.rb index 95971d81..655e7fed 100644 --- a/src/bosh_aws_cpi/lib/cloud/aws/cloud_v1.rb +++ b/src/bosh_aws_cpi/lib/cloud/aws/cloud_v1.rb @@ -376,7 +376,8 @@ def create_stemcell(image_path, stemcell_properties) filters: [{ name: 'image-id', values: props.ami_ids - }] + }], + include_deprecated: true, ).first raise Bosh::Clouds::CloudError, "Stemcell does not contain an AMI in region #{@config.aws.region}" unless available_image