AWS CloudTrail

2015/05/07 - AWS CloudTrail - 8 new api methods

StopLogging (new) Link ¶

Suspends the recording of AWS API calls and log file delivery for the specified trail. Under most circumstances, there is no need to use this action. You can update a trail without stopping it first. This action is the only way to stop recording.

Request Syntax

client.stop_logging(
    Name='string'
)
type Name:

string

param Name:

[REQUIRED]

Communicates to CloudTrail the name of the trail for which to stop logging AWS API calls.

rtype:

dict

returns:

Response Syntax

{}

Response Structure

  • (dict) --

    Returns the objects or data listed below if successful. Otherwise, returns an error.

CreateTrail (new) Link ¶

From the command line, use create-subscription.

Creates a trail that specifies the settings for delivery of log data to an Amazon S3 bucket.

Request Syntax

client.create_trail(
    Name='string',
    S3BucketName='string',
    S3KeyPrefix='string',
    SnsTopicName='string',
    IncludeGlobalServiceEvents=True|False,
    CloudWatchLogsLogGroupArn='string',
    CloudWatchLogsRoleArn='string'
)
type Name:

string

param Name:

[REQUIRED]

Specifies the name of the trail.

type S3BucketName:

string

param S3BucketName:

[REQUIRED]

Specifies the name of the Amazon S3 bucket designated for publishing log files.

type S3KeyPrefix:

string

param S3KeyPrefix:

Specifies the Amazon S3 key prefix that precedes the name of the bucket you have designated for log file delivery.

type SnsTopicName:

string

param SnsTopicName:

Specifies the name of the Amazon SNS topic defined for notification of log file delivery.

type IncludeGlobalServiceEvents:

boolean

param IncludeGlobalServiceEvents:

Specifies whether the trail is publishing events from global services such as IAM to the log files.

type CloudWatchLogsLogGroupArn:

string

param CloudWatchLogsLogGroupArn:

Specifies a log group name using an Amazon Resource Name (ARN), a unique identifier that represents the log group to which CloudTrail logs will be delivered. Not required unless you specify CloudWatchLogsRoleArn.

type CloudWatchLogsRoleArn:

string

param CloudWatchLogsRoleArn:

Specifies the role for the CloudWatch Logs endpoint to assume to write to a user’s log group.

rtype:

dict

returns:

Response Syntax

{
    'Name': 'string',
    'S3BucketName': 'string',
    'S3KeyPrefix': 'string',
    'SnsTopicName': 'string',
    'IncludeGlobalServiceEvents': True|False,
    'CloudWatchLogsLogGroupArn': 'string',
    'CloudWatchLogsRoleArn': 'string'
}

Response Structure

  • (dict) -- Returns the objects or data listed below if successful. Otherwise, returns an error.

    • Name (string) --

      Specifies the name of the trail.

    • S3BucketName (string) --

      Specifies the name of the Amazon S3 bucket designated for publishing log files.

    • S3KeyPrefix (string) --

      Specifies the Amazon S3 key prefix that precedes the name of the bucket you have designated for log file delivery.

    • SnsTopicName (string) --

      Specifies the name of the Amazon SNS topic defined for notification of log file delivery.

    • IncludeGlobalServiceEvents (boolean) --

      Specifies whether the trail is publishing events from global services such as IAM to the log files.

    • CloudWatchLogsLogGroupArn (string) --

      Specifies the Amazon Resource Name (ARN) of the log group to which CloudTrail logs will be delivered.

    • CloudWatchLogsRoleArn (string) --

      Specifies the role for the CloudWatch Logs endpoint to assume to write to a user’s log group.

LookupEvents (new) Link ¶

Looks up API activity events captured by CloudTrail that create, update, or delete resources in your account. Events for a region can be looked up for the times in which you had CloudTrail turned on in that region during the last seven days. Lookup supports five different attributes: time range (defined by a start time and end time), user name, event name, resource type, and resource name. All attributes are optional. The maximum number of attributes that can be specified in any one lookup request are time range and one other attribute. The default number of results returned is 10, with a maximum of 50 possible. The response includes a token that you can use to get the next page of results. The rate of lookup requests is limited to one per second per account.

Request Syntax

client.lookup_events(
    LookupAttributes=[
        {
            'AttributeKey': 'EventId'|'EventName'|'Username'|'ResourceType'|'ResourceName',
            'AttributeValue': 'string'
        },
    ],
    StartTime=datetime(2015, 1, 1),
    EndTime=datetime(2015, 1, 1),
    MaxResults=123,
    NextToken='string'
)
type LookupAttributes:

list

param LookupAttributes:

Contains a list of lookup attributes. Currently the list can contain only one item.

  • (dict) --

    Specifies an attribute and value that filter the events returned.

    • AttributeKey (string) -- [REQUIRED]

      Specifies an attribute on which to filter the events returned.

    • AttributeValue (string) -- [REQUIRED]

      Specifies a value for the specified AttributeKey.

type StartTime:

datetime

param StartTime:

Specifies that only events that occur after or at the specified time are returned. If the specified start time is after the specified end time, an error is returned.

type EndTime:

datetime

param EndTime:

Specifies that only events that occur before or at the specified time are returned. If the specified end time is before the specified start time, an error is returned.

type MaxResults:

integer

param MaxResults:

The number of events to return. Possible values are 1 through 50. The default is 10.

type NextToken:

string

param NextToken:

The token to use to get the next page of results after a previous API call. This token must be passed in with the same parameters that were specified in the the original call. For example, if the original call specified an AttributeKey of 'Username' with a value of 'root', the call with NextToken should include those same parameters.

rtype:

dict

returns:

Response Syntax

{
    'Events': [
        {
            'EventId': 'string',
            'EventName': 'string',
            'EventTime': datetime(2015, 1, 1),
            'Username': 'string',
            'Resources': [
                {
                    'ResourceType': 'string',
                    'ResourceName': 'string'
                },
            ],
            'CloudTrailEvent': 'string'
        },
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) --

    Contains a response to a LookupEvents action.

    • Events (list) --

      A list of events returned based on the lookup attributes specified and the CloudTrail event. The events list is sorted by time. The most recent event is listed first.

      • (dict) --

        Contains information about an event that was returned by a lookup request. The result includes a representation of a CloudTrail event.

        • EventId (string) --

          The CloudTrail ID of the event returned.

        • EventName (string) --

          The name of the event returned.

        • EventTime (datetime) --

          The date and time of the event returned.

        • Username (string) --

          A user name or role name of the requester that called the API in the event returned.

        • Resources (list) --

          A list of resources referenced by the event returned.

          • (dict) --

            Specifies the type and name of a resource referenced by an event.

            • ResourceType (string) --

              The type of a resource referenced by the event returned. When the resource type cannot be determined, null is returned. Some examples of resource types are: Instance for EC2, Trail for CloudTrail, DBInstance for RDS, and AccessKey for IAM. For a list of resource types supported for event lookup, see Resource Types Supported for Event Lookup.

            • ResourceName (string) --

              The name of the resource referenced by the event returned. These are user-created names whose values will depend on the environment. For example, the resource name might be "auto-scaling-test-group" for an Auto Scaling Group or "i-1234567" for an EC2 Instance.

        • CloudTrailEvent (string) --

          A JSON string that contains a representation of the event returned.

    • NextToken (string) --

      The token to use to get the next page of results after a previous API call. If the token does not appear, there are no more results to return. The token must be passed in with the same parameters as the previous call. For example, if the original call specified an AttributeKey of 'Username' with a value of 'root', the call with NextToken should include those same parameters.

UpdateTrail (new) Link ¶

From the command line, use update-subscription.

Updates the settings that specify delivery of log files. Changes to a trail do not require stopping the CloudTrail service. Use this action to designate an existing bucket for log delivery. If the existing bucket has previously been a target for CloudTrail log files, an IAM policy exists for the bucket.

Request Syntax

client.update_trail(
    Name='string',
    S3BucketName='string',
    S3KeyPrefix='string',
    SnsTopicName='string',
    IncludeGlobalServiceEvents=True|False,
    CloudWatchLogsLogGroupArn='string',
    CloudWatchLogsRoleArn='string'
)
type Name:

string

param Name:

[REQUIRED]

Specifies the name of the trail.

type S3BucketName:

string

param S3BucketName:

Specifies the name of the Amazon S3 bucket designated for publishing log files.

type S3KeyPrefix:

string

param S3KeyPrefix:

Specifies the Amazon S3 key prefix that precedes the name of the bucket you have designated for log file delivery.

type SnsTopicName:

string

param SnsTopicName:

Specifies the name of the Amazon SNS topic defined for notification of log file delivery.

type IncludeGlobalServiceEvents:

boolean

param IncludeGlobalServiceEvents:

Specifies whether the trail is publishing events from global services such as IAM to the log files.

type CloudWatchLogsLogGroupArn:

string

param CloudWatchLogsLogGroupArn:

Specifies a log group name using an Amazon Resource Name (ARN), a unique identifier that represents the log group to which CloudTrail logs will be delivered. Not required unless you specify CloudWatchLogsRoleArn.

type CloudWatchLogsRoleArn:

string

param CloudWatchLogsRoleArn:

Specifies the role for the CloudWatch Logs endpoint to assume to write to a user’s log group.

rtype:

dict

returns:

Response Syntax

{
    'Name': 'string',
    'S3BucketName': 'string',
    'S3KeyPrefix': 'string',
    'SnsTopicName': 'string',
    'IncludeGlobalServiceEvents': True|False,
    'CloudWatchLogsLogGroupArn': 'string',
    'CloudWatchLogsRoleArn': 'string'
}

Response Structure

  • (dict) -- Returns the objects or data listed below if successful. Otherwise, returns an error.

    • Name (string) --

      Specifies the name of the trail.

    • S3BucketName (string) --

      Specifies the name of the Amazon S3 bucket designated for publishing log files.

    • S3KeyPrefix (string) --

      Specifies the Amazon S3 key prefix that precedes the name of the bucket you have designated for log file delivery.

    • SnsTopicName (string) --

      Specifies the name of the Amazon SNS topic defined for notification of log file delivery.

    • IncludeGlobalServiceEvents (boolean) --

      Specifies whether the trail is publishing events from global services such as IAM to the log files.

    • CloudWatchLogsLogGroupArn (string) --

      Specifies the Amazon Resource Name (ARN) of the log group to which CloudTrail logs will be delivered.

    • CloudWatchLogsRoleArn (string) --

      Specifies the role for the CloudWatch Logs endpoint to assume to write to a user’s log group.

StartLogging (new) Link ¶

Starts the recording of AWS API calls and log file delivery for a trail.

Request Syntax

client.start_logging(
    Name='string'
)
type Name:

string

param Name:

[REQUIRED]

The name of the trail for which CloudTrail logs AWS API calls.

rtype:

dict

returns:

Response Syntax

{}

Response Structure

  • (dict) --

    Returns the objects or data listed below if successful. Otherwise, returns an error.

DescribeTrails (new) Link ¶

Retrieves settings for the trail associated with the current region for your account.

Request Syntax

client.describe_trails(
    trailNameList=[
        'string',
    ]
)
type trailNameList:

list

param trailNameList:

The trail returned.

  • (string) --

rtype:

dict

returns:

Response Syntax

{
    'trailList': [
        {
            'Name': 'string',
            'S3BucketName': 'string',
            'S3KeyPrefix': 'string',
            'SnsTopicName': 'string',
            'IncludeGlobalServiceEvents': True|False,
            'CloudWatchLogsLogGroupArn': 'string',
            'CloudWatchLogsRoleArn': 'string'
        },
    ]
}

Response Structure

  • (dict) --

    Returns the objects or data listed below if successful. Otherwise, returns an error.

    • trailList (list) --

      The list of trails.

      • (dict) --

        The settings for a trail.

        • Name (string) --

          Name of the trail set by calling CreateTrail.

        • S3BucketName (string) --

          Name of the Amazon S3 bucket into which CloudTrail delivers your trail files.

        • S3KeyPrefix (string) --

          Value of the Amazon S3 prefix.

        • SnsTopicName (string) --

          Name of the existing Amazon SNS topic that CloudTrail uses to notify the account owner when new CloudTrail log files have been delivered.

        • IncludeGlobalServiceEvents (boolean) --

          Set to True to include AWS API calls from AWS global services such as IAM. Otherwise, False.

        • CloudWatchLogsLogGroupArn (string) --

          Specifies an Amazon Resource Name (ARN), a unique identifier that represents the log group to which CloudTrail logs will be delivered.

        • CloudWatchLogsRoleArn (string) --

          Specifies the role for the CloudWatch Logs endpoint to assume to write to a user’s log group.

GetTrailStatus (new) Link ¶

Returns a JSON-formatted list of information about the specified trail. Fields include information on delivery errors, Amazon SNS and Amazon S3 errors, and start and stop logging times for each trail.

Request Syntax

client.get_trail_status(
    Name='string'
)
type Name:

string

param Name:

[REQUIRED]

The name of the trail for which you are requesting the current status.

rtype:

dict

returns:

Response Syntax

{
    'IsLogging': True|False,
    'LatestDeliveryError': 'string',
    'LatestNotificationError': 'string',
    'LatestDeliveryTime': datetime(2015, 1, 1),
    'LatestNotificationTime': datetime(2015, 1, 1),
    'StartLoggingTime': datetime(2015, 1, 1),
    'StopLoggingTime': datetime(2015, 1, 1),
    'LatestCloudWatchLogsDeliveryError': 'string',
    'LatestCloudWatchLogsDeliveryTime': datetime(2015, 1, 1)
}

Response Structure

  • (dict) --

    Returns the objects or data listed below if successful. Otherwise, returns an error.

    • IsLogging (boolean) --

      Whether the CloudTrail is currently logging AWS API calls.

    • LatestDeliveryError (string) --

      Displays any Amazon S3 error that CloudTrail encountered when attempting to deliver log files to the designated bucket. For more information see the topic Error Responses in the Amazon S3 API Reference.

    • LatestNotificationError (string) --

      Displays any Amazon SNS error that CloudTrail encountered when attempting to send a notification. For more information about Amazon SNS errors, see the Amazon SNS Developer Guide.

    • LatestDeliveryTime (datetime) --

      Specifies the date and time that CloudTrail last delivered log files to an account's Amazon S3 bucket.

    • LatestNotificationTime (datetime) --

      Specifies the date and time of the most recent Amazon SNS notification that CloudTrail has written a new log file to an account's Amazon S3 bucket.

    • StartLoggingTime (datetime) --

      Specifies the most recent date and time when CloudTrail started recording API calls for an AWS account.

    • StopLoggingTime (datetime) --

      Specifies the most recent date and time when CloudTrail stopped recording API calls for an AWS account.

    • LatestCloudWatchLogsDeliveryError (string) --

      Displays any CloudWatch Logs error that CloudTrail encountered when attempting to deliver logs to CloudWatch Logs.

    • LatestCloudWatchLogsDeliveryTime (datetime) --

      Displays the most recent date and time when CloudTrail delivered logs to CloudWatch Logs.

DeleteTrail (new) Link ¶

Deletes a trail.

Request Syntax

client.delete_trail(
    Name='string'
)
type Name:

string

param Name:

[REQUIRED]

The name of a trail to be deleted.

rtype:

dict

returns:

Response Syntax

{}

Response Structure

  • (dict) --

    Returns the objects or data listed below if successful. Otherwise, returns an error.