---
updatedAt: 2026-03-01T18:54:16.000Z
agentTools:
  siteIndex: https://techdocs.akamai.com/llms.txt
  projectIndex: https://techdocs.akamai.com/datastream2/llms.txt
---

# Create a stream for Amazon S3 (v2)

```python Python
import requests
import json
from akamai.edgegrid import EdgeGridAuth, EdgeRc
from urllib.parse import urljoin

edgerc = EdgeRc('~/.edgerc.txt')
section = 'default'
baseurl = 'https://%s' % edgerc.get(section, 'host')

session = requests.Session()
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
 

path = '/datastream-config-api/v2/log/streams'
headers = {
  "Content-Type": "application/json",

  "Accept": "application/json"}
payload = {
    "streamName": "DD Stream",
    "groupId": 21484,
    "contractId": "2-FGHIJ",
    "notificationEmails": [
        "useremail1@domain.com",
        "useremail2@domain.com"
    ],
    "properties": [
        {
            "propertyId": 349772
        },
        {
            "propertyId": 349770
        }
    ],
    "datasetFields": [
        {
            "datasetFieldId": 1000
        },
        {
            "datasetFieldId": 1002
        },
        {
            "datasetFieldId": 1023
        }
    ],
    "deliveryConfiguration": {
        "uploadFilePrefix": "logs",
        "uploadFileSuffix": "ds",
        "frequency": {
            "intervalInSeconds": 30
        },
        "format": "STRUCTURED",
        "fieldDelimiter": "SPACE"
    },
    "destination": {
        "path": "ds2-logs",
        "displayName": "S3Destination",
        "bucket": "datastream.akamai.com",
        "region": "ap-south-1",
        "accessKey": "1T2ll1H4dXWx5itGhpc7FlSbvvOvky1098nTiitn",
        "secretAccessKey": "AKIA6DK7TDQLVGZ3MYP1",
        "destinationType": "S3"
    },
    "collectMidgress": true
} 
querystring = {
  "activate": True
}  

result = session.get(urljoin(baseurl, path), headers=headers, json=payload, querystring=querystring)
print(result.status_code)
print(json.dumps(result.json(), indent=2)) 
```

```node Node
const EdgeGrid = require("akamai-edgegrid");
const os = require("os");
const edgercPath = os.homedir + "/.edgerc.txt";
const edgercSection = "default";
const eg = new EdgeGrid({
  path: edgercPath,
  section: edgercSection,
});

eg.auth({
  path: `/datastream-config-api/v2/log/streams`,
  method: "POST",
  headers: {
    "Content-Type": "application/json",

    Accept: "application/json",
  },
  body: {
    streamName: "DD Stream",
    groupId: 21484,
    contractId: "2-FGHIJ",
    notificationEmails: ["useremail1@domain.com", "useremail2@domain.com"],
    properties: [
      {
        propertyId: 349772,
      },
      {
        propertyId: 349770,
      },
    ],
    datasetFields: [
      {
        datasetFieldId: 1000,
      },
      {
        datasetFieldId: 1002,
      },
      {
        datasetFieldId: 1023,
      },
    ],
    deliveryConfiguration: {
      uploadFilePrefix: "logs",
      uploadFileSuffix: "ds",
      frequency: {
        intervalInSeconds: 30,
      },
      format: "STRUCTURED",
      fieldDelimiter: "SPACE",
    },
    destination: {
      path: "ds2-logs",
      displayName: "S3Destination",
      bucket: "datastream.akamai.com",
      region: "ap-south-1",
      accessKey: "1T2ll1H4dXWx5itGhpc7FlSbvvOvky1098nTiitn",
      secretAccessKey: "AKIA6DK7TDQLVGZ3MYP1",
      destinationType: "S3",
    },
    collectMidgress: true,
  },
  qs: {
    activate: true,
  },
});
eg.send(function (error, response, body) {
  console.log(JSON.stringify(JSON.parse(body), null, 2));
});
```

```shell cURL
activate=true

egcurl --eg-section default --request POST \
  --url "https://hostname/datastream-config-api/v2/log/streams?activate=$activate" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --data '
{
    "streamName": "DD Stream",
    "groupId": 21484,
    "contractId": "2-FGHIJ",
    "notificationEmails": [
        "useremail1@domain.com",
        "useremail2@domain.com"
    ],
    "properties": [
        {
            "propertyId": 349772
        },
        {
            "propertyId": 349770
        }
    ],
    "datasetFields": [
        {
            "datasetFieldId": 1000
        },
        {
            "datasetFieldId": 1002
        },
        {
            "datasetFieldId": 1023
        }
    ],
    "deliveryConfiguration": {
        "uploadFilePrefix": "logs",
        "uploadFileSuffix": "ds",
        "frequency": {
            "intervalInSeconds": 30
        },
        "format": "STRUCTURED",
        "fieldDelimiter": "SPACE"
    },
    "destination": {
        "path": "ds2-logs",
        "displayName": "S3Destination",
        "bucket": "datastream.akamai.com",
        "region": "ap-south-1",
        "accessKey": "1T2ll1H4dXWx5itGhpc7FlSbvvOvky1098nTiitn",
        "secretAccessKey": "AKIA6DK7TDQLVGZ3MYP1",
        "destinationType": "S3"
    },
    "collectMidgress": true
}'
```

```json Response Example
{
  "streamName": "DD Stream",
  "streamId": 7050,
  "streamVersion": 1,
  "groupId": 21484,
  "contractId": "2-FGHIJ",
  "properties": [
    {
      "propertyId": 349772,
      "propertyName": "example.com"
    },
    {
      "propertyId": 349770,
      "propertyName": "example.akamai.com"
    }
  ],
  "datasetFields": [
    {
      "datasetFieldId": 1000,
      "datasetFieldName": "CP code",
      "datasetFieldJsonKey": "cp"
    },
    {
      "datasetFieldId": 1002,
      "datasetFieldName": "Request ID",
      "datasetFieldJsonKey": "reqId"
    },
    {
      "datasetFieldId": 1023,
      "datasetFieldName": "Cookie",
      "datasetFieldJsonKey": "cookie"
    }
  ],
  "destination": {
    "path": "ds2-logs",
    "displayName": "S3Destination",
    "bucket": "datastream.akamai.com",
    "region": "ap-south-1",
    "destinationType": "S3",
  },
  "deliveryConfiguration": {
    "uploadFilePrefix": "logs",
    "uploadFileSuffix": "ds",
    "fieldDelimiter": "SPACE",
    "frequency": {
      "intervalInSeconds": 30
    },
    "format": "STRUCTURED"
  },
  "latestVersion": 1,
  "productId": "Dynamic_Site_Accelerator",
  "streamStatus": "ACTIVATING",
  "createdBy": "johndoe",
  "createdDate": "2022-02-05T13:31:30Z",
  "modifiedBy": "johndoe",
  "modifiedDate": "2022-02-05T13:31:30Z",
  "notificationEmails": [
    "useremail1@domain.com",
    "useremail2@domain.com"
  ],
  "collectMidgress": true
}
```

# Set up authorization

<!-- python@1-4 -->
<!-- node@1-8 -->
<!-- shell@3-6 -->

Before you can this API, you need to [Create authentication credentials](https://techdocs.akamai.com/developer/docs/set-up-authentication-credentials).

Then, you can use these code samples to apply the token values to your requests.

# Name the stream

<!-- python@20 -->
<!-- node@19 -->
<!-- shell@9 -->

In the `streamName` field, enter a meaningful, human-readable name for your stream. It's useful for identification purposes.

# Fetch group information

<!-- python@21-22 -->
<!-- node@20-21 -->
<!-- shell@10-11 -->

Run the [List groups](https://techdocs.akamai.com/datastream2/reference/get-groups) operation to get and store these values:

- the `groupId` of the group the product you want to monitor belongs to.

- `contractId` of the contract that belongs to the selected group.

# Set e-mail notifications

<!-- python@23-25 -->
<!-- node@22 -->
<!-- shell@12-14 -->

You can optionally enter a comma-delimited list of e-mail addresses to get notifications about events related to the stream (such as activating and deactivating it). 

If you omit this member, DataStream will not send e-mail notifications.

# Choose the properties

<!-- python@27-33 -->
<!-- node@23-29 -->
<!-- shell@16-22 -->

Fetch properties available for the group you previously selected. To do that, use the stored `groupId` in the [List properties by group](https://techdocs.akamai.com/datastream2/reference/get-group-properties) operation and store the `propertyId` values that you want to monitor in this stream. 

Enter them in the `properties` array of the request body.

# Choose the data set fields

<!-- python@35-44 -->
<!-- node@31-40 -->
<!-- shell@24-33 -->

Run the [List data set fields](https://techdocs.akamai.com/datastream2/reference/get-dataset-fields) operation and pick the `datasetFieldId` values of the fields that you want to monitor in your logs.

Values for these fields will appear in the log lines in the order you list them in the `datasetFields` array.

# Build the delivery configuration object

<!-- python@46-53 -->
<!-- node@42-49 -->
<!-- shell@35-42 -->

Build a `deliveryConfiguration` object where you specify how the logs are delivered.

# Set the filename's prefix and suffix

<!-- python@47-48 -->
<!-- node@43-44 -->
<!-- shell@36-37 -->

You can specify the `uploadFilePrefix` and `uploadFileSuffix` fields. These values are added to the name of the log file sent to your destination.

If omitted, the logs will have the `ak` prefix and `ds` suffix by default.

For more details, see [Dynamic time variables](https://techdocs.akamai.com/datastream2/v2/reference/custom-log-field#dynamic-time-variables).

# Set the log bundling frequency

<!-- python@49-50 -->
<!-- node@45-46 -->
<!-- shell@38-40 -->

In the `frequency` object, set the `intervalInSeconds` to `30` or `60` seconds to specify the time after which the API bundles your logs into a file and sends to a destination.

# Choose the log format and delimiter

<!-- python@52-53 -->
<!-- node@48-49 -->
<!-- shell@41-42 -->

Set the `format` that you want to receive your logs in, either `JSON` or `STRUCTURED`. 

For the `STRUCTURED` value, set the `fieldDelimiter` to `SPACE`. 

For the `JSON` value, skip the `fieldDelimiter` field.

# Configure the destination

<!-- python@55-63 -->
<!-- node@51-59 -->
<!-- shell@44-52 -->

Use the `destination` array to configure destination details, such as the upload path and authentication credentials.

# Set the upload path

<!-- python@56 -->
<!-- node@52 -->
<!-- shell@45 -->

Specify the `path` to the folder within your Amazon S3 bucket where you want to upload store your logs.  If the folders don't exist in the bucket, Amazon creates them for you.

This field supports [Dynamic time variables](https://techdocs.akamai.com/datastream2/docs/dynamic-time-variables). See [Amazon S3 naming](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html) conventions.

# Name the destination

<!-- python@57 -->
<!-- node@53 -->
<!-- shell@46 -->

Enter a meaningful `displayName` to identify the destination.

# Set the S3 bucket

<!-- python@58 -->
<!-- node@54 -->
<!-- shell@47 -->

Specify the name of the `bucket` in the S3 account where you want to upload store logs. See [Working with Amazon S3 Buckets](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingBucket.html) in AWS.

# Set the AWS region

<!-- python@59 -->
<!-- node@55 -->
<!-- shell@48 -->

Enter the AWS `region` code where your bucket resides. See [Available region coded](https://docs.aws.amazon.com/general/latest/gr/rande.html#region-names-codes).

# Enter the access keys

<!-- python@60-61 -->
<!-- node@56-57 -->
<!-- shell@49-50 -->

Specify the `accessKey` and `secretAccessKey` you use to authenticate requests to your Amazon S3 account. See [Managing access keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey_API) AWS API.

# Enter the destination type

<!-- python@62 -->
<!-- node@58 -->
<!-- shell@51 -->

In `destinationType`, enter `S3`, the identifier for the Amazon S3 destination in DataStream 2.

# Enable logging midgress traffic

<!-- python@64 -->
<!-- node@60 -->
<!-- shell@53 -->

Set `collectMidgress` to `true` if you want to to get data on traffic from within the Akamai platform, such as between two edge servers.

# Activate the stream

<!-- python@66-67 -->
<!-- node@62-64 -->
<!-- shell@1 -->

Optionally, set the `activate` field to `true` to start activating the stream on request. The stream activates in approximately 60 minutes after making the request.

If you set this field to `false`, the stream remains inactive after the request.

You can activate or deactivate the stream at your convenience by running the [Activate a stream](https://techdocs.akamai.com/datastream2/reference/put-stream-activate) or [Deactivate a stream](https://techdocs.akamai.com/datastream2/reference/put-stream-deactivate) operations.

# Call the API

<!-- node@1-68 -->

Run POST on the request URL with the request body object.

# Store the response values



The response's object returns the `streamId` and `streamVersion` values for the stream version you created.

You can use these values for other operations, such as [Get a stream](https://techdocs.akamai.com/datastream2/reference/get-stream) to list stream details.