Paws XXXXVIII (Way too many 'I' s)

Well I think it is a first here in the Paws patrol. I spent the day plunging away with CloudFront and I have no new Paws issues but I did learn and important practical lesson about using CloudFront.

I got stuck on the 'UpdateCloudFrontOriginAccessIdentity' call.

It seemed simple enough


$s3->UpdateCloudFrontOriginAccessIdentity(
    CloudFrontOriginAccessIdentityConfig => {
        CallerReference => 'Some text here',
        Comment         => 'Mr Pooppy buthole did this',
  },
  Id=> 'E3D5Y5RWA05QO1',
);

but I kept running into this error;

The request failed because it didn't meet the preconditions in one or more request-header fields.

Ok what is that?

After playing about for a long time and re-reading a number of differing API docs I finally figured it out.

I am in one of those cases where I need to follow a set protocol to get the action to work.

First I have to make a call to 'GetCloudFrontOriginAccessIdentity' like this;


  $ListObjectsV2Output = $s3->GetCloudFrontOriginAccessIdentityConfig(
    Id=>'E3D5Y5RWA05QO1',
);

with the 'Id' I am interested in and that will give me this me this;


bless( {
    '_request_id' => '1ee7bc4b-1bc6-4b7e-9a51-16bc4139198c',
    'ETag' => 'E2J612BD0LRDHQ',
    'CloudFrontOriginAccessIdentityConfig' => bless( {
            'CallerReference' => 'some test here',
                'Comment' => 'This is Mr Poopy Buthole calling'
    },
     'Paws::CloudFront::CloudFrontOriginAccessIdentityConfig' )
 }, 'Paws::CloudFront::GetCloudFrontOriginAccessIdentityConfigResult' );

Now I have three things

  1. the Id 'E3D5Y5RWA05QO1' of my identity which never changes;
  2. the Etag 'E2J612BD0LRDHQ' of my identity which I guess is best describe as the current id and
  3. CallerReference which is a ref value that I supplied when I crested the identity.

You need all three to update.

So now my call looks like this


ListObjectsV2Output = $s3->UpdateCloudFrontOriginAccessIdentity(
 CloudFrontOriginAccessIdentityConfig => {
    CallerReference => 'some test here',
    Comment         => 'Mr Pooppy buthole did this',
  },
  Id      => 'E3D5Y5RWA05QO1',
  IfMatch => 'E2J612BD0LRDHQ',  
);

and now I am getting this


bless( {
'CloudFrontOriginAccessIdentity' => bless( {
'Id' => 'E3D5Y5RWA05QO1',
'S3CanonicalUserId' => '84...71',
'CloudFrontOriginAccessIdentityConfig' => bless( {
'CallerReference' => 'some test here',
'Comment' => 'Mr Pooppy buthole did this'
},
'Paws::CloudFront::CloudFrontOriginAccessIdentityConfig' )
},
'Paws::CloudFront::CloudFrontOriginAccessIdentity' ),

So all is good.

I did get one more fail with the above again nothing to do with Paws what I did was I had a mismatch between the two ' CallerReference' values. Seems these have to match up or you will get a 'You cannot update the value of CallerReference.' Good to know.

I can see why they did this, AWS is trying to prevent double 'Submits' so you have to like one call up with another. My choice of 'some test here' was not a good one I should of used a hires time-stamp or alike of get a real unique id.

Now onto the 'Delete' action and this time I followed the correct procedure by getting the Identity I wanted to delete and finding out its Etag

and with the call


$s3->DeleteCloudFrontOriginAccessIdentity(
Id=>'EY07SKBZ90C5A',
IfMatch=>'E1DHMR4TNGBY5N'
);

I get a perfect response


$VAR1 = bless( {
'_request_id' => 'ff8462e0-82eb-4e58-8cd5-95276eb535d2'
}, 'Paws::API::Response' )

Things are looking up.

6c4edc448d3d9de120678d30523e547f.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations