Set off AWS IoT Greengrass element deployments from AWS CodeCommit


    As computing energy extends into Web of Factor (IoT) units, software program turns into an increasing number of essential to creating choices, processing knowledge, and offering perception to finish customers on the machine. Units are the spine of many companies and functions. Whatever the use case, prospects profit from fast, widespread deployment of software program updates and enhancements throughout machine fleets. With AWS IoT Greengrass V2, AWS prospects can simply construct, deploy, and handle customized machine software program as AWS IoT Greengrass parts. AWS IoT Greengrass handles actions similar to monitoring the element variations, managing the fleets of units, and orchestrating element updates.

    On this weblog, we are going to display find out how to automate the deployment of element adjustments on AWS IoT Greengrass. This resolution reduces the time it takes builders to deploy customized machine software program throughout a fleet from minutes to seconds, saving builders useful time and bettering agility.

    This resolution makes use of a centralized code repository with Steady Integration and Steady Deployment (CI/CD) to help in following DevOps greatest practices. For extra details about CI/CD and DevOps on AWS, reference the Practising Steady Integration and Steady Supply on AWS whitepaper.

    On this article, we are going to current a technique for automating the deployment of customized AWS IoT Greengrass parts. AWS IoT Greengrass consists of AWS-provided parts so as to add widespread performance to your units and likewise permits for customized parts creation. Customized parts might analyze knowledge, show a front-end dashboard, or run an software with intermittent connectivity to the cloud. For demonstration functions, we will probably be utilizing three pre-built parts. Nonetheless, this resolution is well adaptable to parts you might have already got working in your surroundings.

    This resolution clones a Github repository to an AWS CodeCommit repository for example implementation. Different implementations can be utilized so long as the code is deployed to CodeCommit. In the beginning of the steps under, we are going to define find out how to clone a repository from Github into AWS CodeCommit. Nonetheless, different code repositories could be imported into AWS CodeCommit if mandatory on your use case. For extra info on migrating code to an AWS CodeCommit repo, see the documentation right here.

    For this stroll by means of, it is best to have the next stipulations:

    Set up AWS CLI

    Be sure to have put in and setup AWS CLI with the required permissions:

    Set up CDK

    Here’s a information to Get Began with AWS CDK:

    Please confirm the cdk package deal model put in is 2.x or increased.

    The answer makes use of an AWS CodeCommit repo to retailer the element code, a Lambda operate to set off the construct, and AWS CodeBuild to orchestrate the deployment of the up to date element. Lastly, AWS IoT Greengrass pushes the up to date element out to the units.ggv2-cdk-arch

    • A commit is made to the AWS CodeCommit repository. An Amazon CloudWatch Occasion occasion has been configured such that any time a commit is made to the configured repository, the occasion happens.
    • An AWS Lambda operate is triggered by the Amazon CloudWatch Occasion.  The AWS Lambda operate first determines if the commit was made on a file that’s a part of the supply code for the element. If that’s the case, it saves the element identify(s) as AWS CodeBuild Venture Surroundings Variables and begins the AWS CodePipeline.
    • AWS CodeBuild job is triggered by the AWS CodePipeline. The AWS CodeBuild job runs a shell script which deploys the element to the units utilizing the AWS IoT Greengrass API.

    AWS Cloud Improvement Package (AWS CDK) is a framework for outlining cloud infrastructure in code, and provisioning it by way of AWS CloudFormation. In case you are new to the AWS CDK, observe the getting began information. 

    The CDK will deploy the next sources within the AWS Account:

    • AWS CodePipeline
    • AWS Lambda
    • CodeBuild
    • Amazon S3
    • [Optional] Amazon EC2
    • AWS CLI v2
    • AWS CDK v2

    Create and clone code repository

    • Create CodeCommit Venture
      • Go to AWS CodeCommit Console
      • Choose Create Repository
      • Present identify for the repository. For instance ggv2-cdk-blog-test
      • Select Create
    • Clone the CodeCommit repository in your native machine, for instance if the CodeCommit repository is called  ggv2-cdk-blog:
    • In an effort to deploy the cdk you will want to repeat the cdk contents from github repository:
      • To simply copy the contents of this github challenge to your new challenge, copy to your CodeCommit challenge listing, and unzip
        • Observe: The .gitignore file is a part of, for those who don’t discover the file after unzip test your settings to view hidden information within the IDE

    Supply code updates

    Please replace following attributes in cdk.json file with acceptable values:

    • account
      • Account ID of your AWS account, for instance: 1234567890
    • codecommit_repository_arn
      • For instance: arn:aws:codecommit:us-east-1:111111111111:MyDemo*
    • area
    • create_core_device
      • acceptable values are true or false
      • Even for those who select false ensure to offer a reputation for an current core machine within the possibility core_device_name and core_device_group_name
    • default_branch_name
      •  department to trace for the CodePipeline. For instance: most important
    •   core_device_name
      •  The identify of your new/current Greengrass core machine.
    •  core_device_group_name
      • The identify of your new/current Greengrass core machine group.
    •  project_prefix

    Deploy CDK pipeline

    • Arrange your virtualenv for Python. You might want to make use of python3 in alternative of python, relying in your native python configuration.
    • Bootstrap your account/area for CDK – exchange the suitable variables (i.e. ACCOUNT-ID, REGION, ADMIN-PROFILE) earlier than executing.
      • Instructions to run:
        • export CDK_NEW_BOOTSTRAP=1 
          npx cdk bootstrap --cloudformation-execution-policies arn:aws:iam::aws:coverage/AdministratorAccess 
        •  Observe: Confirm you’ve gotten the AdministratorAccess coverage in your AWS account or you may customise the coverage for use by AWS CDK as a way to create AWS sources
        • For instance, like this:
        • export CDK_NEW_BOOTSTRAP=1                                    
          npx cdk bootstrap --cloudformation-execution-policies arn:aws:iam::aws:coverage/<CustomPolicy> 
    • Commit updates to the repository and deploy the CDK app. You might have to git push origin <most important department identify> , as a substitute of git push
    •  Non-compulsory: To replace in your personal challenge, run the next:

    The code repository for this weblog has pattern customized AWS IoT Greengrass parts, that can show the message Howdy World within the log file of the element. The subsequent part will present extra details about constructing your personal AWS IoT Greengrass parts.

    Including your personal AWS IoT Greengrass parts

    The code on this weblog makes use of Greengrass Improvement Package (gdk cli) as a way to construct and publish Greengrass parts. For extra info please test this documentation.

    So as to add new parts to the challenge, create a brand new element listing within the parts listing. Ensure that your parts embrace the next:

    • gdk-config.json (GDK configuration file)
    • buildspec.yml (for CodeBuild)
    • necessities.txt (for Python dependencies; presently utilized by offered buildspec.yml examples)

    Constructing AWS IoT Greengrass parts

    Listed here are 5 tricks to construct AWS IoT Greengrass v2 Parts. For extra info please refer under:

    Cleansing Up

    • CDK Cleanup
      • Run the next command out of your terminal on the trail the place the code repository exists (Instance: Customers/johndoe/desktop/ggv2-cdk-blog ~ %)
      • cdk destroy


    You now have setup a DevOps pipeline for a number of parts in the identical code repository. With these enhancements, when a developer pushes code updates to parts within the repository, the AWS IoT Greengrass V2 parts routinely deploy a brand new model with the updates. Count on to see builders be capable of iterate quicker, creating enterprise worth and innovation at a brand new tempo.

    Be taught extra about AWS IoT Greengrass by means of this palms on workshop.  For extra details about public parts for AWS IoT Greengrass, please go to

    In regards to the Authors

    Jon Slominski is a Sr. Options Architect with the Prototyping & Cloud Engineering (PACE) crew at AWS. Constructing prototypes centered on IoT, AI/ML, and robotics, Jon helps prospects innovate and envision the artwork of the potential. Exterior of labor, Jon enjoys spending time and touring together with his spouse and daughters.
    Joyson Neville Lewis is an IoT Knowledge Architect at AWS Skilled Providers. He has labored as a Software program/Knowledge engineer earlier than diving into the Conversational AI and Industrial IoT area the place he works with firms to attach the dots between enterprise and AI utilizing Voice Assistant/Chatbot and IoT options.
    Jack Tanny is an Affiliate Knowledge/ML Engineer in AWS’s Skilled Providers crew. He builds options that use knowledge to unravel issues and unlock enterprise worth for our prospects. In his free time, you may often discover Jack within the mountains, biking, snowboarding, or tenting.


    Please enter your comment!
    Please enter your name here