Creating Amazon IoT Greengrass resources with Amazon CloudFormation - Amazon IoT Greengrass
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Creating Amazon IoT Greengrass resources with Amazon CloudFormation

Amazon IoT Greengrass is integrated with Amazon CloudFormation, a service that helps you to model and set up your Amazon resources so that you can spend less time creating and managing your resources and infrastructure. You create a template that describes all the Amazon resources that you want (such as component versions and deployments), and Amazon CloudFormation provisions and configures those resources for you.

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

Amazon IoT Greengrass and Amazon CloudFormation templates

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

Amazon IoT Greengrass supports creating component versions and deployments in Amazon CloudFormation. For more information, including examples of JSON and YAML templates for component versions and deployments, see the Amazon IoT Greengrass resource type reference in the Amazon CloudFormation User Guide.

ComponentVersion template example

The following is the YAML template for a version of a simple component. The JSON recipe includes line breaks for readability.

Parameters: ComponentVersion: Type: String Resources: TestSimpleComponentVersion: Type: AWS::GreengrassV2::ComponentVersion Properties: InlineRecipe: !Sub - "{\n \"RecipeFormatVersion\": \"2020-01-25\",\n \"ComponentName\": \"component1\",\n \"ComponentVersion\": \"${ComponentVersion}\",\n \"ComponentType\": \"aws.greengrass.generic\",\n \"ComponentDescription\": \"This\",\n \"ComponentPublisher\": \"You\",\n \"Manifests\": [\n {\n \"Platform\": {\n \"os\": \"darwin\"\n },\n \"Lifecycle\": {},\n \"Artifacts\": []\n },\n {\n \"Lifecycle\": {},\n \"Artifacts\": []\n }\n ],\n \"Lifecycle\": {\n \"install\": {\n \"script\": \"yuminstallpython\"\n }\n }\n }" - { ComponentVersion: !Ref ComponentVersion }

Deployment template example

The following is a YAML file defining a simple template for a deployment.

Parameters: ComponentVersion: Type: String TargetArn: Type: String Resources: TestDeployment: Type: AWS::GreengrassV2::Deployment Properties: Components: component1: ComponentVersion: !Ref ComponentVersion TargetArn: !Ref TargetArn DeploymentName: CloudFormationIntegrationTest DeploymentPolicies: FailureHandlingPolicy: DO_NOTHING ComponentUpdatePolicy: TimeoutInSeconds: 5000 Action: SKIP_NOTIFY_COMPONENTS ConfigurationValidationPolicy: TimeoutInSeconds: 30000 Outputs: TestDeploymentArn: Value: !Sub - arn:${AWS::Partition}:greengrass:${AWS::Region}:${AWS::AccountId}:deployments:${DeploymentId} - DeploymentId: !GetAtt TestDeployment.DeploymentId

Learn more about Amazon CloudFormation

To learn more about Amazon CloudFormation, see the following resources: