Logging that requires additional permissions [V2]
Some AWS services use a new method to send their logs. This is a flexible method that enables you to set up log delivery from these services to one or more of the following destinations: CloudWatch Logs, Amazon S3, or Firehose and X-Ray for trace delivery.
A working log delivery consists of three elements:
-
A
DeliverySource, which is a logical object that represents the resource(s) that actually send the logs. -
A
DeliveryDestination, which is a logical object that represents the actual delivery destination. -
A
Delivery, which connects a delivery source to delivery destination
To configure logs delivery between a supported AWS service and a destination, you must do the following:
-
Create a delivery source with PutDeliverySource.
-
Create a delivery destination with PutDeliveryDestination.
-
If you are delivering logs cross-account, you can use only Amazon S3 and Firehose destinations. You must use PutDeliveryDestinationPolicy in the destination account to assign an IAM policy to the destination. This policy authorizes creating a delivery from the delivery source in account A to the delivery destination in account B. For cross-account delivery, you must manually create the permission policies yourself. For setup examples, see Cross-account delivery example.
-
Create a delivery by pairing exactly one delivery source and one delivery destination, by using CreateDelivery.
Log delivery setup examples
The following examples create the delivery source and delivery destination in the same AWS account. Replace the source resource ARN and log type with values supported by the service that generates the logs. These examples don't require a delivery destination policy.
Create a delivery source
Create the delivery source, and then use one of the destination examples that follow.
aws logs put-delivery-source \ --name my-delivery-source \ --resource-arnsource-resource-arn\ --log-typelog-type
Create a delivery to CloudWatch Logs
Create a delivery destination for an existing log group.
aws logs put-delivery-destination \ --name my-cwl-delivery-destination \ --delivery-destination-configuration \ "destinationResourceArn=arn:aws:logs:region:account-id:log-group:log-group-name"
Create the delivery.
aws logs create-delivery \ --delivery-source-name my-delivery-source \ --delivery-destination-arn arn:aws:logs:region:account-id:delivery-destination:my-cwl-delivery-destination
Create a delivery to Amazon S3
Create a delivery destination for an existing bucket.
aws logs put-delivery-destination \ --name my-s3-delivery-destination \ --delivery-destination-configuration \ "destinationResourceArn=arn:aws:s3:::bucket-name"
Create the delivery.
aws logs create-delivery \ --delivery-source-name my-delivery-source \ --delivery-destination-arn arn:aws:logs:region:account-id:delivery-destination:my-s3-delivery-destination
To configure a destination prefix, suffix path, or Hive-compatible path, see Amazon S3 object key format.
Create a delivery to Firehose
Create a delivery destination for an existing DirectPut delivery stream.
aws logs put-delivery-destination \ --name my-firehose-delivery-destination \ --delivery-destination-configuration \ "destinationResourceArn=arn:aws:firehose:region:account-id:deliverystream/delivery-stream-name"
Create the delivery.
aws logs create-delivery \ --delivery-source-name my-delivery-source \ --delivery-destination-arn arn:aws:logs:region:account-id:delivery-destination:my-firehose-delivery-destination
Create a delivery to X-Ray
For trace delivery, use a source service and log type that supports delivery to X-Ray. Create the logical X-Ray delivery destination.
aws logs put-delivery-destination \ --name my-xray-delivery-destination \ --delivery-destination-type XRAY
Create the delivery.
aws logs create-delivery \ --delivery-source-name my-delivery-source \ --delivery-destination-arn arn:aws:logs:region:account-id:delivery-destination:my-xray-delivery-destination
To verify the delivery, use the following command.
aws logs describe-deliveries \ --delivery-source-name-prefix my-delivery-source
The following sections provide the details of the permissions you need to have when you are signed in to set up log delivery to each type of destination, using the V2 process. These permissions can be granted to an IAM role that you are signed in with.
Important
It is your responsibility to remove log delivery resources after deleting the log-generating resource. To do so, follow these steps.
-
Delete the
Deliveryby using the DeleteDelivery operation. -
Delete the
DeliverySourceby using the DeleteDeliverySource operation. -
If the
DeliveryDestinationassociated with theDeliverySourcethat you just deleted is used only for this specificDeliverySource, then you can remove it by using the DeleteDeliveryDestinations operation.