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. It uses AWS Signature Version 4 to authenticate requests to S3.

Tip

You can use this Amazon S3 connector to copy data from any S3-compatible storage providers e.g. Google Cloud Storage. Specify the corresponding service URL in the linked service configuration.

Required permissions

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

  • For copy activity execution:: s3:GetObject and s3:GetObjectVersion for Amazon S3 Object Operations.
  • For Data Factory GUI authoring: s3:ListAllMyBuckets and s3:ListBucket/s3:GetBucketLocation for Amazon S3 Bucket Operations permissions are additionally required for operations like test connection and browse/navigate file paths. If you don't want to grant these permission, skip test connection in linked service creation page and specify the path directly in dataset settings.

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

Getting started

You can use one of the following tools or SDKs to use the copy activity with a pipeline. Select a link for step-by-step instructions:

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
serviceUrl Specify the custom S3 endpoint if you are copying data from a S3-compatible storage provider other than the official Amazon S3 service. For example, to copy data from Google Cloud Storage, specify https://storage.googleapis.com. No
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

Tip

Specify the custom S3 service URL if you are copying data from a S3-compatible storage other than the official Amazon S3 service.

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 for Copy/Lookup activity, No for GetMetadata activity
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 supported for both folder part and file name 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"
See more example in Folder and file filter examples. Use ^ to escape if your actual folder/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. If not specified, the latest version will be fetched. No
modifiedDatetimeStart Files filter based on the attribute: Last Modified. The files will be selected if their last modified time are within the time range between modifiedDatetimeStart and modifiedDatetimeEnd. The time is applied to UTC time zone in the format of "2018-12-01T05:00:00Z".

The properties can be NULL which mean no file attribute filter will be applied to the dataset. When modifiedDatetimeStart has datetime value but modifiedDatetimeEnd is NULL, it means the files whose last modified attribute is greater than or equal with the datetime value will be selected. When modifiedDatetimeEnd has datetime value but modifiedDatetimeStart is NULL, it means the files whose last modified attribute is less than the datetime value will be selected.
No
modifiedDatetimeEnd Files filter based on the attribute: Last Modified. The files will be selected if their last modified time are within the time range between modifiedDatetimeStart and modifiedDatetimeEnd. The time is applied to UTC time zone in the format of "2018-12-01T05:00:00Z".

The properties can be NULL which mean no file attribute filter will be applied to the dataset. When modifiedDatetimeStart has datetime value but modifiedDatetimeEnd is NULL, it means the files whose last modified attribute is greater than or equal with the datetime value will be selected. When modifiedDatetimeEnd has datetime value but modifiedDatetimeStart is NULL, it means the files whose last modified attribute is less than the datetime value will be selected.
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",
            "modifiedDatetimeStart": "2018-12-01T05:00:00Z",
            "modifiedDatetimeEnd": "2018-12-01T06:00:00Z",
            "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>"
            }
        }
    }
]

Folder and file filter examples

This section describes the resulting behavior of the folder path and file name with wildcard filters.

bucket key recursive Source folder structure and filter result (files in bold are retrieved)
bucket Folder*/* false bucket
    FolderA
        File1.csv
        File2.json
        Subfolder1
            File3.csv
            File4.json
            File5.csv
    AnotherFolderB
        File6.csv
bucket Folder*/* true bucket
    FolderA
        File1.csv
        File2.json
        Subfolder1
            File3.csv
            File4.json
            File5.csv
    AnotherFolderB
        File6.csv
bucket Folder*/*.csv false bucket
    FolderA
        File1.csv
        File2.json
        Subfolder1
            File3.csv
            File4.json
            File5.csv
    AnotherFolderB
        File6.csv
bucket Folder*/*.csv true bucket
    FolderA
        File1.csv
        File2.json
        Subfolder1
            File3.csv
            File4.json
            File5.csv
    AnotherFolderB
        File6.csv

Next steps

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