- Newest
- Most votes
- Most comments
Hello.
I assume that you have already created S3, but you can create an SSM inventory using the following CloudFormation template.
The bucket policy to be set for the S3 bucket is described in the following document.
https://docs.aws.amazon.com/systems-manager/latest/userguide/inventory-create-resource-data-sync.html#datasync-before-you-begin
AWSTemplateFormatVersion: 2010-09-09
Description: Systems Managers Inventory
Parameters:
S3Bucket:
Type: String
SSMInventory:
Type: AWS::SSM::Association
Properties:
AssociationName: Inventory-Association
Name: AWS-GatherSoftwareInventory
Targets:
- Key: InstanceIds
Values:
- "*"
ResourceDataSync:
Type: 'AWS::SSM::ResourceDataSync'
Properties:
SyncName: Resource-Data-Sync
BucketName: !Ref S3Bucket
BucketRegion: !Sub ${AWS::Region}
SyncFormat: JsonSerDe
While there isn't a direct CloudFormation resource specifically for enabling AWS Systems Manager Inventory, you can achieve this by creating a Systems Manager association using CloudFormation. Here's an example of how you could structure a CloudFormation template to enable Systems Manager Inventory:
AWSTemplateFormatVersion: '2010-09-09' Description: 'Enable AWS Systems Manager Inventory' Resources: InventoryAssociation: Type: 'AWS::SSM::Association' Properties: Name: 'AWS-GatherSoftwareInventory' AssociationName: 'InventoryCollection' ScheduleExpression: 'rate(1 day)' Targets: - Key: 'InstanceIds' Values: - '*' Parameters: applications: - 'Enabled' awsComponents: - 'Enabled' networkConfig: - 'Enabled' windowsUpdates: - 'Enabled' instanceDetailedInformation: - 'Enabled' services: - 'Enabled'
This template creates an AWS::SSM::Association resource that:
- Uses the AWS-GatherSoftwareInventory document, which is the Systems Manager document for collecting inventory.
- Sets up a schedule to run inventory collection daily.
- Targets all instances in the account.
- Enables collection of various inventory types like applications, AWS components, network configuration, Windows updates, instance detailed information, and services.
You can modify the ScheduleExpression and the Parameters section to adjust the frequency of inventory collection and the types of inventory data collected according to your needs.
Remember to ensure that your instances have the necessary IAM permissions to communicate with Systems Manager and that the SSM Agent is installed and running on your instances for this to work effectively.
Sources
Configuring inventory collection - AWS Systems Manager
Using Application Manager to manage AWS CloudFormation templates - AWS Systems Manager
Relevant content
- asked 2 years ago

This template returns an error, "Resource handler returned message: "Error occurred during operation 'CreateAssociation'.""