AWS for Industries

Deploy Android Automotive on AWS Graviton Using AWS CloudFormation

AWS for Automotive offers Software-Defined Vehicle (SDV) solutions, helping to address the needs of the automotive industry to handle increasing software complexity, improve cost control, and enhance product quality. AWS is innovating on SDV solutions that include the ability to deploy virtualized automotive hardware and software stacks on AWS. This includes building and deploying Google’s open-source Android Automotive Operating System (AAOS), used for automotive cockpit software, on AWS.

This blog is the first in a multi-part series, where we focus on building Continuous Integration/Continuous Deployment (CI/CD) pipelines for AAOS and in-vehicle infotainment (IVI) applications on AWS,helping to create more collaborative workflow opportunities, and minimizing the OEM’s and/or suppliers’ dependence on local physical hardware.

This first part details the use of AWS CloudFormation, allowing you to automate, test, and deploy your infrastructure for AAOS stacks running on AWS Graviton instances for OEMs and their suppliers developing vehicle user experiences and IVI applications.

Future installments of this blog series will describe additional topics, including:

1. How to deploy AAOS on AWS using AWS Cloud Development Kit (AWS CDK) with AWS CodeBuild; and

2. CI/CD pipelines that build and deploy IVI applications onto the IVI stack with well-known development tools.

A modern vehicle can contain more than 100 million lines of code, executed by hundreds of independent Electronic Control Units (ECU). An ECU is an embedded system with one or more system-on-a-chip (SoC) components and microcontroller units (MCU). For automotive software development teams, there is increasing pressure to lower costs and increase quality. This coincides with stricter safety and security regulations. All of these factors combine to make testing even more crucial to the software development life cycle (SDLC). As software becomes a more important part of functionality, cost, safety, and quality, software updates have become more common than replacing hardware. The best approach to handle these contemporary issues in automotive software development and maintenance is to use agile methodology, continuous testing, and automation, which is more easily facilitated by developing ECUs on the AWS cloud.

Run AAOS on Graviton using AWS CloudFormation

With AWS services, it is rare that there is only ever one solution to a problem, but instead a range of solutions which may suit different situations This is also the case with deployment of AAOS on AWS. To simplify your build process, you can utilize the capabilities of AWS CloudFormation.

AWS CloudFormation automates the deployment of infrastructure into your AWS account, simplifying both the provisioning and deprovisioning of resources. The following figure is an architecture diagram which shows how you can fully automate the build and deployment of AAOS on a Graviton-based instance using CloudFormation.

The provided CloudFormation template will launch resources including an Amazon S3 Bucket and two EC2 instances, along with the resources required to complete the build. We have provided two versions of the CloudFormation template, which you can choose according to your needs regarding cost and convenience.

1. This version launches using AWS EC2 Spot Instances (for cost savings). Spot instances will require more oversight to use and manage, but will cost less.

2. This version launches using AWS EC2 On-Demand Instances (see pricing details on AWS), for persistent access to the environment, however do refer to the pricing details.

Using either of these CloudFormation templates (don’t use both, but choose one or the other based upon your needs), the first EC2 instance will download AAOS and carry out the build steps copying the completed build images into the Amazon S3 Bucket. The second instance waits for the files to appear in Amazon S3 and once they are available, will configure AAOS to start running, exposing the HTTP Interface.

Figure 1 - AAOS on AWS ArchitectureFigure 1 – AAOS on AWS Architecture

Prerequisites

Region Region Name Region Region Name
eu-west-1 Europe (Ireland) eu-west-2 Europe (London)
ap-southeast-1 Asia Pacific (Singapore) eu-central-1 Europe (Frankfurt)
us-west-2 US West (Oregon) us-east-1 US East (N. Virginia)
us-east-2 US East (Ohio) ap-northeast-1 Asia Pacific (Tokyo)

Note: This solution will incur cost, for more information on how to calculate an estimated cost please use https://calculator.aws/.

Solution Steps

Build, Deploy, and Access AAOS Stack on AWS Graviton
1. First download the CloudFormation stack yaml file and log in to AWS Management Console and go to the CloudFormation landing page or click on the following CloudFormation link which will automatically take you to CloudFormation page, per the following figure.

Figure 2 – AWS CloudFormation Console Landing PageFigure 2 – AWS CloudFormation Console Landing Page

2. In the top right select “Create Stack”, “With new resources (Standard)”, on the next Screen select “Template is ready “and then “Upload a template file”, click “Choose file” and navigate to and select the “aaos-cf-template.yaml” you downloaded, then click “Next”, per the following figure.

Figure 3 – Create Stack in AWS CloudFormation Console Using Provided YAML FileFigure 3 – Create Stack in AWS CloudFormation Console Using Provided YAML File

3. On the next screen provide a unique stack name and ensure it follows the same naming convention as for Amazon S3 buckets, then click “Next”. I have chosen the name “cicdstack”, per the following figure.

Figure 4 – Specify AWS CloudFormation Stack Name and DetailsFigure 4 – Specify AWS CloudFormation Stack Name and Details

4. On the next window, leave all options on defaults and click “Next”, per the following figure.

Figure 5 – Configure Stack Options in AWS CloudFormationFigure 5 – Configure Stack Options in AWS CloudFormation

5. In the final window, review your CloudFormation stack details, acknowledge the message around creation of IAM resources, then click “Submit “, per the following figure.

Figure 6 – Review (continued) AWS CloudFormation Stack DetailsFigure 6 – Review (continued) AWS CloudFormation Stack Details

Figure 7 – Review AWS CloudFormation Stack Details and Click Submit to Create StackFigure 7 – Review AWS CloudFormation Stack Details and Click Submit to Create Stack

6. CloudFormation will now create all the resources required to build and run the AAOS stack. This process may take around 2 hours to complete. Once the stack creation is complete, you can check the creation status on the CloudFormation console interface, as shown in the following figure.

Figure 8 – Check AWS CloudFormation Stack Status for the Deployed and Running AAOS StackFigure 8 – Check AWS CloudFormation Stack Status for the Deployed and Running AAOS Stack

7. Under the Resources tab, you will see a list of all of the Resources deployed for the Stack and their creation statuses, per the following figure.

Figure 9 – See all Resources Deployed in your AWS CloudFormation Stack Deploying AAOSFigure 9 – See all Resources Deployed in your AWS CloudFormation Stack Deploying AAOS

8. You can view the progress in Amazon CloudWatch Logs “AAOSLogs-*Region*” log group, where *Region* is the AWS Region in which you chose to deploy the solution. Each instance, that is the build instance and the target instance will output to its own stream. Once everything has completed, the target instance will generate the HTTP address from which you can access the AAOS Interface into the “AAOSTarget-*Region*-*Stackname*” log steam, it will be something similar to : “https://**Instance-IP**:8443“, per the figure below.

Figure 10 – Check Status of Solution Deployment in Amazon CloudWatch LogsFigure 10 – Check Status of Solution Deployment in Amazon CloudWatch Logs

9. To confirm that the stack creation has produced the desired result, you can check the web address and access the AAOS instance once the build process completes. You will be able to see the AAOS web interface address under the Outputs tab of the CloudFormation interface, per the following figure.

Figure 11 – Refer to the Outputs Tab in CloudFormation for Web Address to Your AAOS InstanceFigure 11 – Refer to the Outputs Tab in CloudFormation for Web Address to Your AAOS Instance

10. By accessing the “AAOSWebInterface” link and clicking “Connect”, you should see the screen depicted in the following figure. We recommend using the Chrome browser for best compatibility. You will need to acknowledge (eg, click “Advanced“) that the connection is not secure. Addressing the https security aspects accessing AAOS in a web browser will be covered in a future installment of this blog series.

Figure 12 – Accessing the AAOS User Interface in Web BrowserFigure 12 – Accessing the AAOS User Interface in Web Browser

Developing and Deploying a basic Android application on your AAOS instance
The above steps demonstrated how to build, deploy, and access your AAOS instance. However, developers often desire to design, build, and deploy applications to run on the AAOS stack.

The following steps illustrate how to create a basic Android app in Android Studio, connect to your instance, and deploy and run the application on your AAOS stack.

1. In this case, we are developing on our AAOS stack using Android Studio, which is shown in the following screenshot. Download and install Android Studio to your preferred development environment by following the instructions provided during download and install. When you install Android Studio, be sure to also install the Android SDK, as you will need the SDK’s platform tools to develop for your AAOS device.

Figure 13 – Use Android Studio to Develop and Deploy Applications to your AAOS DeviceFigure 13 – Use Android Studio to Develop and Deploy Applications to your AAOS Device

2. Using the command line tool on your operating system, change to the directory where you installed Android Studio. We are using Android Debug Bridge (ADB) for Android Studio to communicate with our remote device on AWS. On the command line, enter the following command:

.\adb connect x.x.x.x:6520”, where x.x.x.x is the IP of your EC2 instance as shown in the CloudFormation Outputs tab, time using port 6520 to communicate using ADB protocol, as shown in the following figure. In the Android SDK platform-tools, the adb.exe executable and ‘connect’ command are being used.

Once you are successfully connected, you will see a response, “connected to your IP x.x.x.x:6520”.

Figure 14 – Connect Android Studio to Your AAOS Device on AWS Using ADB

3. Once you have verified the connection to the ADP port of your AAOS device, as shown in the previous figure, your remote device should also appear in Android Studio under the Device Manager’s “Physical devices” tab. It will be listed as “Google Cuttlefish arm64 auto”, with a green indicator for connection success, as shown the following figure.

Figure 15 – Your Remote AAOS Device Shown Connected as a Physical Device in Android Studio Device ManagerFigure 15 – Your Remote AAOS Device Shown Connected as a Physical Device in Android Studio Device Manager

4. We can now start developing an Android application, as shown in the following figure. For simplicity, we are deploying a “Hello from AWS!”, app in the Android “apk” application format. Further details can be explored in the documentation accompanying Android Studio.

Figure 16 – Developing a Basic Application for your AAOS Device in Android StudioFigure 16 – Developing a Basic Application for your AAOS Device in Android Studio

5. Once we have completed the development of our application, we can deploy it by clicking on the green Play (green arrow) button at the top of Android Studio in the previous image. Compiling the application and deploying it to the remote AAOS device may take a few moments.

As shown in the following image, our new application should appear on the AAOS instance in the browser shortly after it has compiled and deployed over ADB.

Figure 17 – Our Basic Android Application Appears on the AAOS Device Running on Amazon EC2 GravitonFigure 17 – Our Basic Android Application Appears on the AAOS Device Running on Amazon EC2 Graviton

Congratulations, you have developed and are using your first Android Automotive application on an AAOS device running on Amazon EC2 Graviton!

How to stop your AAOS target EC2 instance when not in use to help save cost
In order to save cost, we advise that you stop the AAOS target EC2 instance when it is not being used.

We recommend you stop the Cuttlefish Virtual Device (CVD) service on the instance before stopping the EC2 instance, in order to avoid corruption of the device image, using these instructions to issue commands on the EC2 instance.

Then, navigate to your target EC2 instance in the AWS Console, and select ‘Instance state’, ‘Stop instance’.

When you restart your AAOS target EC2 instance, you will find that it likely has a new IP address. Note this IP address for re-connecting to the AAOS device again per the following instructions You will also need to restart CVD per instructions to restart. As well, if you want to re-connect Android Studio to your AAOS device, you will need to restart ADB per the instructions you followed previously.

Cleaning Up Resources

To remove the created resources, you must first empty the Amazon S3 Bucket, visit S3 in the AWS Console, find the bucket created by the stack “aaos-build-output-**Region**-**AccountID**-**StackName**” and delete all objects within the bucket. Once the bucket is empty return to AWS CloudFormation in the console, find the stack you created and click on “Delete”, and confirm that you want to delete all resources.

Conclusion

Methods that help shorten time-to-market, lower cost, and simplify development are beneficial to automotive software development. The Android Automotive stack comprises a large portion of today’s automotive in-cockpit OS usage by developers. You can simplify your IVI development on AAOS by virtualizing instances on Amazon EC2, thus parallelizing development processes, helping to create more collaborative workflow opportunities, and minimizing OEM and supplier dependence on local physical hardware, so your software is largely tested and complete before you reach the point of testing on physical hardware.

Scott Nelson

Scott Nelson

Scott is Senior Industry Specialist Consultant in AWS Professional Services (ProServe). With 25 years in the spaces of automotive hardware, software, silicon, wireless, content, networks, and cloud services, he applies his broad and deep expertise across the automotive and manufacturing industries to bring new ideas to life and transform businesses. With the transformation to software-defined products, Scott has been enabling new workflows and solutions in the cloud to help accelerate product development and improve customer experiences and business outcomes.

Dan Stroud

Dan Stroud

Dan is a Senior Solutions Architect based in London, with a background in Automotive, he works to support and enable Enterprise Customers in the UK Automotive & Manufacturing sector. He is also a builder, with a passion for Embedded & IoT Development, Edge Technologies and Predictive Maintenance.

H Jafari

H Jafari

H Jafari is a Solutions Architect at Amazon Web Services. He works with Enterprise Software & SaaS customers to design, build, and deploy technology solutions on AWS. He assists customers in adopting best practices while deploying solutions on AWS.

Isha Dua

Isha Dua

Isha Dua is a Senior Solutions Architect based in San Francisco Bay Area. She helps AWS Enterprise customers grow by understanding their goals and challenges, and guiding them on how they can architect their applications in a cloud native manner while making sure they are resilient and scalable. She’s passionate about machine learning technologies and Environmental Sustainability.