Specifying resources with AWS CloudFormation - Amazon Personalize

Specifying resources with AWS CloudFormation

Amazon Personalize is integrated with AWS CloudFormation, a service that helps you to model and set up your AWS resources so that you can spend less time creating and managing your resources and infrastructure. You create a template that describes all the AWS resources that you can specify (such as Amazon Personalize dataset groups). CloudFormation then provisions and configures those resources for you.

When you use CloudFormation, you can reuse your template to set up your Amazon Personalize resources consistently and repeatedly. Describe your resources once, and then provision the same resources over and over in multiple AWS accounts and Regions.

Amazon Personalize and CloudFormation templates

To provision and configure resources for Amazon Personalize and related services, you must understand CloudFormation templates. Templates are formatted text files in JSON or YAML. These templates describe the resources that you want to provision in your CloudFormation stacks. If you're unfamiliar with JSON or YAML, you can use CloudFormation Designer to help you get started with CloudFormation templates. For more information, see What is CloudFormation Designer? in the AWS CloudFormation User Guide.

Amazon Personalize supports specifying datasets, dataset groups, dataset import jobs, schemas, and solutions in CloudFormation. For more information, see the Amazon Personalize resource type reference in the AWS CloudFormation User Guide.

Example CloudFormation templates for Amazon Personalize resources

The following CloudFormation template examples show you how to specify different Amazon Personalize resources.

CreateDatasetGroup

JSON
{ "AWSTemplateFormatVersion":"2010-09-09", "Resources":{ "MyDatasetGroup": { "Type": "AWS::Personalize::DatasetGroup", "Properties": { "Name": "my-dataset-group-name" } } } }
YAML
AWSTemplateFormatVersion: 2010-09-09 Resources: MyDatasetGroup: Type: 'AWS::Personalize::DatasetGroup' Properties: Name: my-dataset-group-name

CreateDataset

JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "MyDataset": { "Type": "AWS::Personalize::Dataset", "Properties": { "Name": "my-dataset-name", "DatasetType": "Interactions", "DatasetGroupArn": "arn:aws:personalize:us-west-2:123456789012:dataset-group/dataset-group-name", "SchemaArn": "arn:aws:personalize:us-west-2:123456789012:schema/schema-name", "DatasetImportJob": { "JobName": "my-import-job-name", "DataSource": { "DataLocation": "s3://amzn-s3-demo-bucket/file-name.csv" }, "RoleArn": "arn:aws:iam::123456789012:role/personalize-role" } } } } }
YAML
AWSTemplateFormatVersion: 2010-09-09 Resources: MyDataset: Type: 'AWS::Personalize::Dataset' Properties: Name: my-dataset-name DatasetType: Interactions DatasetGroupArn: 'arn:aws:personalize:us-west-2:123456789012:dataset-group/dataset-group-name' SchemaArn: 'arn:aws:personalize:us-west-2:123456789012:schema/schema-name' DatasetImportJob: JobName: my-import-job-name DataSource: DataLocation: 's3://amzn-s3-demo-bucket/file-name.csv' RoleArn: 'arn:aws:iam::123456789012:role/personalize-role'

CreateSchema

JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "MySchema": { "Type": "AWS::Personalize::Schema", "Properties": { "Name": "my-schema-name", "Schema": "{\"type\": \"record\",\"name\": \"Interactions\", \"namespace\": \"com.amazonaws.personalize.schema\", \"fields\": [ { \"name\": \"USER_ID\", \"type\": \"string\" }, { \"name\": \"ITEM_ID\", \"type\": \"string\" }, { \"name\": \"TIMESTAMP\", \"type\": \"long\"}], \"version\": \"1.0\"}" } } } }
YAML
AWSTemplateFormatVersion: 2010-09-09 Resources: MySchema: Type: AWS::Personalize::Schema Properties: Name: "my-schema-name" Schema: >- {"type": "record","name": "Interactions", "namespace": "com.amazonaws.personalize.schema", "fields": [ { "name": "USER_ID", "type": "string" }, { "name": "ITEM_ID", "type": "string" }, { "name": "TIMESTAMP", "type": "long"}], "version": "1.0"}

CreateSolution

JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "MySolution": { "Type": "AWS::Personalize::Solution", "Properties": { "Name": "my-solution-name", "DatasetGroupArn": "arn:aws:personalize:us-west-2:123456789012:dataset-group/my-dataset-group-name", "RecipeArn": "arn:aws:personalize:::recipe/aws-user-personalization", "SolutionConfig": { "EventValueThreshold" : ".05" } } } } }
YAML
AWSTemplateFormatVersion: 2010-09-09 Resources: MySolution: Type: 'AWS::Personalize::Solution' Properties: Name: my-solution-name DatasetGroupArn: >- arn:aws:personalize:us-west-2:123456789012:dataset-group/my-dataset-group-name RecipeArn: 'arn:aws:personalize:::recipe/aws-user-personalization' SolutionConfig: EventValueThreshold: '.05'

Learn more about CloudFormation

To learn more about CloudFormation, see the following resources: