Skip to content

Instantly share code, notes, and snippets.

@jtroberts83
Last active August 28, 2018 03:05
Show Gist options
  • Save jtroberts83/168353874d2e86b1b05a02af20f546f4 to your computer and use it in GitHub Desktop.
Save jtroberts83/168353874d2e86b1b05a02af20f546f4 to your computer and use it in GitHub Desktop.
import boto3
from botocore.client import Config
from datetime import datetime, timedelta
import json
bucket = 'yours3bucket'
KeyArnKey = 'MyKMSArns.csv'
KMSClient = boto3.client('kms')
def lambda_handler(event, context):
s3resource = boto3.resource('s3', config=Config(signature_version='s3v4'), region_name="us-east-1")
AllKMSKeys = KMSClient.list_keys()
KeyArnList = []
for key in AllKMSKeys['Keys']:
KeyARN = key['KeyArn']
KeyArnList.append(KeyARN)
locals3Client = boto3.client('s3',
config=Config(signature_version='s3v4'),
region_name="us-east-1"
)
KeyArnList = (json.dumps(KeyArnList)).replace("[","")
KeyArnList = KeyArnList.replace("]","")
KeyArnList = KeyArnList.replace(" ","")
response = locals3Client.put_object(
Body=KeyArnList,
Bucket=bucket,
Key=KeyArnKey,
ContentEncoding='ascii'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment