Ninad Gaikwad
Ninad Gaikwad

Reputation: 4480

'S3' object has no attribute 'put_object_retention'

I'm trying to implement the object lock function introduced recently by AWS s3. The code works perfectly when i run it locally. But as soon as i deploy it on amazon it breaks and gives me the error. I have tried deploying it using zappa, ECS as well as plain lambda. It appears that amazon python packages don't have the latest boto3. This is the code I am trying to make work:

    s3_client = boto3.client('s3', aws_access_key_id=access_key, aws_secret_access_key=secret_key)
response = s3_client.put_object_retention(
    Bucket=bucket,
    Key='docker.docx',
    Retention={
        'Mode': 'COMPLIANCE',
        'RetainUntilDate': datetime.datetime(2019, 1, 6)
    },
    VersionId='xN7ixBbDRaUoO99rpUzO6R8E30xox2Ng'
)

My ultimate goal is to deploy it in a flask app. But I am currently stuck as I can't even get this to work on any aws deployment.

Upvotes: 2

Views: 836

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 270174

put_object_retention() is a rather new feature.

You will need to update your boto3 to a newer version:

sudo pip install boto3 --upgrade

I just upgraded to v1.9.74 and it worked.

Upvotes: 4

Related Questions