Inventory Management using Operations as Code
AWS Systems Manager
is a collection of features that enable IT Operations that we will explore throughout this lab.
There are set up tasks
that must be satisfied prior to using Systems Manager to manage your EC2 instances or on-premises systems in hybrid environments
- You must use a supported operating system
- Supported operating systems include versions of Windows, Amazon Linux, Ubuntu Server, RHEL, and CentOS
- The SSM Agent must be installed
- The SSM Agent for Windows also requires PowerShell 3.0 or later to run some SSM documents
- Your EC2 instances must have outbound internet access
- You must access Systems Manager in a supported region
- Systems Manager requires IAM roles
- for instances that will process commands
- for users executing commands
SSM Agent is installed by default on:
- Amazon Linux base AMIs dated 2017.09 and later
- Windows Server 2016 instances
- Instances created from Windows Server 2003-2012 R2 AMIs published in November 2016 or later
There is no additional charge for AWS Systems Manager
. You only pay for your underlying AWS resources managed or created by AWS Systems Manager (e.g., Amazon EC2 instances or Amazon CloudWatch metrics). You only pay for what you use as you use it. There are no minimum fees and no upfront commitments.
4.1 Setting up Systems Manager
- Use your administrator account to access the Systems Manager console at https://console.aws.amazon.com/systems-manager/.
- Choose Managed Instances from the navigation bar. If you have not satisfied the pre-requisites for Systems Manager, you will arrive at the AWS Systems Manager Managed Instances page.
- Create an Instance Profile for Systems Manager managed instances:
- Navigate to the IAM console
- In the navigation pane, choose Roles.
- Then choose Create role.
- In the Select type of trusted entity section, verify that the default AWS service is selected.
- In the Choose the service that will use this role section, scroll past the first reference to EC2 (EC2 Allows EC2 instances to call AWS services on your behalf) and choose EC2 from within the field of services. This will open the Select your use case section further down the page.
- In the Select your use case section, choose EC2 Role for Simple Systems Manager to select it.
- Then choose Next: Permissions.
- Under Attached permissions policy, verify that AmazonEC2RoleforSSM is listed, and then choose Next: Review.
- In the Review section:
- Enter a Role name, such as
- Accept the default in the Role description.
- Choose Create role.
- Apply this role to the instances you wish to manage with Systems Manager:
- Navigate to the EC2 Console
and choose Instances.
- Select the first instance and then choose Actions, Security, and Modify IAM Role.
- Under Modify IAM Role, select ManagedInstancesRole from the drop down list and choose Save.
- Repeat this process, assigning ManagedInstancesRole to each of the 3 remaining instances.
- Return to the Systems Manager console
and choose Managed Instances from the navigation bar. Periodically choose Managed Instances until your instances begin to appear in the list. Over the next couple of minutes your instances will populate into the list as managed instances.
NoteIf desired, you can use a more restrictive permission set
to grant access to Systems Manager.
4.2 Create a Second CloudFormation Stack
- Create a second CloudFormation stack using the procedure in 3.1 with the following changes:
- In the Specify Details section, define a Stack name, such as
- Specify the InstanceProfile using the
ManagedInstancesRole you defined.
- Define the Workload Name as
Systems Manager: Inventory
You can use AWS Systems Manager Inventory
to collect operating system (OS), application, and instance metadata from your Amazon EC2 instances and your on-premises servers or virtual machines (VMs) in your hybrid environment. You can query the metadata to quickly understand which instances are running the software and configurations required by your software policy, and which instances need to be updated.
4.3 Using Systems Manager Inventory to Track Your Instances
- Under Instances & Nodes in the AWS Systems Manager navigation bar, choose Inventory.
- Scroll down in the window to the Corresponding managed instances section. Inventory currently contains only the instance data available from the EC2
- Choose the InstanceID of one of your systems.
- Examine each of the available tabs of data under the Instance ID heading.
- Inventory collection must be specifically configured and the data types to be collected must be specified
- Choose Inventory in the navigation bar.
- Choose Setup Inventory in the top right corner of the window
- In the Setup Inventory screen, define targets for inventory:
- Under Specify targets by, select Specifying a tag
- Under Tags specify
Environment for the key and
OELabIPM for the value
NoteYou can select all managed instances in this account, ensuring that all managed instances will be inventoried. You can constrain inventoried instances to those with specific tags, such as Environment or Workload. Or you can manually select specific instances for inventory.
- Schedule the frequency with which inventory is collected. The default and minimum period is 30 minutes
- For Collect inventory data every, accept the default 30 Minute(s)
- Under parameters, specify what information to collect with the inventory process
- Review the options and select the defaults
- (Optional) If desired, you may specify an S3 bucket to receive the inventory execution logs (you will need to create a destination bucket for the logs
prior to proceeding):
- Check the box next to Sync inventory execution logs to an S3 bucket under the Advanced options.
- Provide an S3 bucket name.
- (Optional) Provide an S3 bucket prefix.
- Choose Setup Inventory at the bottom of the page (it can take up to 10 minutes to deploy a new inventory policy to an instance).
- To create a new inventory policy, from Inventory, choose Setup inventory.
- To edit an existing policy, from State Manager in the left navigation menu, select the association and choose Edit.
NoteYou can create multiple Inventory specifications. They will each be stored as associations within Systems Manager State Manager.
Systems Manager: State Manager
In State Manager, an association
is the result of binding configuration information that defines the state you want your instances to be in to the instances themselves. This information specifies when and how you want instance-related operations to run that ensure your Amazon EC2 and hybrid infrastructure is in an intended or consistent state.
An association defines the state you want to apply to a set of targets. An association includes three components and one optional set of components:
- A document that defines the state
- A schedule
- (Optional) Runtime parameters.
When you performed the Setup Inventory actions, you created an association in State Manager.
4.4 Review Association Status
- Under Actions in the navigation bar, select State Manager. At this point, the Status may show that the inventory activity has not yet completed.
- Choose the single Association id that is the result of your Setup Inventory action.
- Examine each of the available tabs of data under the Association ID heading.
- Choose Edit.
- Enter a name under Name - optional to provide a more user friendly label to the association, such as
InventoryAllInstances (white space is not permitted in an Association Name).
Inventory is accomplished through the following:
- The activities defined in the AWS-GatherSoftwareInventory command document.
- The parameters provided in the Parameters section are passed to the document at execution.
- The targets are defined in the Targets section.
ImportantIn this example there is a single target, the wildcard. The wildcard matches all instances making them all targets.
- The schedule for this activity is defined under Specify schedule and Specify with to use a CRON/Rate expression on a 30 minute interval.
- There is the option to specify Output options.
NoteIf you change the command document, the Parameters section will change to be appropriate to the new command document.
- Navigate to Managed Instances under Instances and Nodes in the navigation bar. An Association Status has been established for the inventoried instances under management.
- Choose one of the Instance ID links to go to the inventory of the instance. The Inventory tab is now populated and you can track associations and their last activity under the Associations tab.
- Navigate to Compliance under Instances & Nodes in the navigation bar. Here you can view the overall compliance status of your managed instances in the Compliance Summary and the individual compliance status of systems in the Corresponding managed instances section below.
NoteThe inventory activity can take up to 10 minutes to complete. While waiting for the inventory activity to complete, you can proceed with the next section.
Systems Manager: Compliance
You can use AWS Systems Manager Configuration Compliance
to scan your fleet of managed instances for patch compliance and configuration inconsistencies. You can collect and aggregate data from multiple AWS accounts and Regions, and then drill down into specific resources that aren’t compliant.
By default, Configuration Compliance displays compliance data about Systems Manager Patch Manager patching and Systems Manager State Manager associations. You can also customize the service and create your own compliance types based on your IT or business requirements. You can also port data to Amazon Athena and Amazon QuickSight to generate fleet-wide reports.