Copy data from Amazon Simple Storage Service using Azure Data Factory

This article outlines how to use the Copy Activity in Azure Data Factory to copy data from Amazon S3. It builds on the copy activity overview article that presents a general overview of copy activity.

Supported capabilities

You can copy data Amazon S3 to any supported sink data store. For a list of data stores that are supported as sources or sinks by the copy activity, see the Supported data stores table.

Specifically, this Amazon S3 connector supports copying files as-is or parsing files with the supported file formats and compression codecs.

Required permissions

To copy data from Amazon S3, make sure you have been granted the following permissions:

  • s3:GetObject and s3:GetObjectVersion for Amazon S3 Object Operations.
  • s3:ListBucket or s3:GetBucketLocation for Amazon S3 Bucket Operations. If you are using the Data Factory Copy Wizard, s3:ListAllMyBuckets is also required.

For details about the full list of Amazon S3 permissions, see Specifying Permissions in a Policy.

Getting started

You can create a pipeline with the copy activity by using one of the following tools or SDKs. Select a link to go to a tutorial with step-by-step instructions to create a pipeline with a copy activity.

The following sections provide details about properties that are used to define Data Factory entities specific to Amazon S3.

Linked service properties

The following properties are supported for Amazon S3 linked service:

Property Description Required
type The type property must be set to AmazonS3. Yes
accessKeyId ID of the secret access key. Yes
secretAccessKey The secret access key itself. Mark this field as a SecureString to store it securely in Data Factory, or reference a secret stored in Azure Key Vault. Yes
connectVia The Integration Runtime to be used to connect to the data store. You can use Azure Integration Runtime or Self-hosted Integration Runtime (if your data store is located in private network). If not specified, it uses the default Azure Integration Runtime. No

Note

This connector requires access keys for IAM account to copy data from Amazon S3. Temporary Security Credential is not supported.

Here is an example:

{
    "name": "AmazonS3LinkedService",
    "properties": {
        "type": "AmazonS3",
        "typeProperties": {
            "accessKeyId": "<access key id>",
            "secretAccessKey": {
                    "type": "SecureString",
                    "value": "<secret access key>"
            }
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

Dataset properties

For a full list of sections and properties available for defining datasets, see the datasets article. This section provides a list of properties supported by Amazon S3 dataset.

To copy data from Amazon S3, set the type property of the dataset to AmazonS3Object. The following properties are supported:

Property Description Required
type The type property of the dataset must be set to: AmazonS3Object Yes
bucketName The S3 bucket name. Wildcard filter is not supported. Yes
key The name or wildcard filter of S3 object key under the specified bucket. Applies only when "prefix" property is not specified.

The wildcard filter is only supported for file name part but not folder part. Allowed wildcards are: * (matches zero or more characters) and ? (matches zero or single character).
- Example 1: "key": "rootfolder/subfolder/*.csv"
- Example 2: "key": "rootfolder/subfolder/???20180427.txt"
Use ^ to escape if your actual file name has wildcard or this escape char inside.
No
prefix Prefix for the S3 object key. Objects whose keys start with this prefix are selected. Applies only when "key" property is not specified. No
version The version of the S3 object, if S3 versioning is enabled. No
format If you want to copy files as-is between file-based stores (binary copy), skip the format section in both input and output dataset definitions.

If you want to parse or generate files with a specific format, the following file format types are supported: TextFormat, JsonFormat, AvroFormat, OrcFormat, ParquetFormat. Set the type property under format to one of these values. For more information, see Text Format, Json Format, Avro Format, Orc Format, and Parquet Format sections.
No (only for binary copy scenario)
compression Specify the type and level of compression for the data. For more information, see Supported file formats and compression codecs.
Supported types are: GZip, Deflate, BZip2, and ZipDeflate.
Supported levels are: Optimal and Fastest.
No

Tip

To copy all files under a folder, specify bucketName for bucket and prefix for folder part.
To copy a single file with a given name, specify bucketName for bucket and key for folder part plus file name.
To copy a subset of files under a folder, specify bucketName for bucket and key for folder part plus wildcard filter.

Example: using prefix

{
    "name": "AmazonS3Dataset",
    "properties": {
        "type": "AmazonS3Object",
        "linkedServiceName": {
            "referenceName": "<Amazon S3 linked service name>",
            "type": "LinkedServiceReference"
        },
        "typeProperties": {
            "bucketName": "testbucket",
            "prefix": "testFolder/test",
            "format": {
                "type": "TextFormat",
                "columnDelimiter": ",",
                "rowDelimiter": "\n"
            },
            "compression": {
                "type": "GZip",
                "level": "Optimal"
            }
        }
    }
}

Example: using key and version (optional)

{
    "name": "AmazonS3Dataset",
    "properties": {
        "type": "AmazonS3",
        "linkedServiceName": {
            "referenceName": "<Amazon S3 linked service name>",
            "type": "LinkedServiceReference"
        },
        "typeProperties": {
            "bucketName": "testbucket",
            "key": "testFolder/testfile.csv.gz",
            "version": "XXXXXXXXXczm0CJajYkHf0_k6LhBmkcL",
            "format": {
                "type": "TextFormat",
                "columnDelimiter": ",",
                "rowDelimiter": "\n"
            },
            "compression": {
                "type": "GZip",
                "level": "Optimal"
            }
        }
    }
}

Copy activity properties

For a full list of sections and properties available for defining activities, see the Pipelines article. This section provides a list of properties supported by Amazon S3 source.

Amazon S3 as source

To copy data from Amazon S3, set the source type in the copy activity to FileSystemSource (which includes Amazon S3). The following properties are supported in the copy activity source section:

Property Description Required
type The type property of the copy activity source must be set to: FileSystemSource Yes
recursive Indicates whether the data is read recursively from the sub folders or only from the specified folder. Note when recursive is set to true and sink is file-based store, empty folder/sub-folder will not be copied/created at sink.
Allowed values are: true (default), false
No

Example:

"activities":[
    {
        "name": "CopyFromAmazonS3",
        "type": "Copy",
        "inputs": [
            {
                "referenceName": "<Amazon S3 input dataset name>",
                "type": "DatasetReference"
            }
        ],
        "outputs": [
            {
                "referenceName": "<output dataset name>",
                "type": "DatasetReference"
            }
        ],
        "typeProperties": {
            "source": {
                "type": "FileSystemSource",
                "recursive": true
            },
            "sink": {
                "type": "<sink type>"
            }
        }
    }
]

Next steps

For a list of data stores supported as sources and sinks by the copy activity in Azure Data Factory, see supported data stores.