Skip to content

Instantly share code, notes, and snippets.

aws cloudtrail describe-trails
aws cloudtrail delete-trail --name my-trail
aws cloudtrail stop-logging --name my-trail
aws cloudtrail update-trail --name my-trail --s3-bucket-name not-my-bucket
aws cloudtrail update-trail --name my-trail --no-is-multi-region-trail --no-include-global-service-events
{
"Version": "2012-10-17",
"Id": "Key policy created for CloudTrail",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "[account-id]/[user-id]"
},
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AWSCloudTrailAclCheck20150319",
"Effect":"Allow",
"Principal":{
"Service":"cloudtrail.amazonaws.com"
},
"Action":"s3:GetBucketAcl",
{
"Owner": {
"DisplayName": "[user-name]",
"ID": "[user-id]"
},
"Grants": [
{
"Grantee": {
"Type": "CanonicalUser",
"DisplayName": "[user-name]",
import json
import urllib
import boto3
s3 = boto3.client('s3')
def lambda_handler(event, context):
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key']).decode('utf8')
try:
{
"LambdaFunctionConfigurations": [
{
"LambdaFunctionArn": "arn:aws:lambda:[my-region]:[account-id]:function:[my-function]",
"Id": "[my-guid]",
"Events": [
"s3:ObjectCreated:*"
]
}
]