- Newest
- Most votes
- Most comments
The issue you're experiencing with creating AWS::CloudTrail::ResourcePolicy resources for CloudTrail EventDataStore using CloudFormation is likely due to the default resource policy that AWS automatically creates when you create an EventDataStore.
When you create an EventDataStore, AWS CloudTrail automatically creates a default resource policy for it. This default policy is why you're seeing an "empty" policy in the console and getting an "AlreadyExists" error when trying to create a new one through CloudFormation.
To resolve this issue, you have a few options:
-
Use the AWS CLI or SDK to update the existing resource policy instead of trying to create a new one through CloudFormation. You can use the
put-resource-policycommand in the AWS CLI for CloudTrail. -
If you want to manage the resource policy through CloudFormation, you might need to use a custom resource that calls the AWS SDK to update the existing policy rather than trying to create a new one.
-
Another approach could be to create the EventDataStore without a resource policy initially, then immediately update it with your desired policy. This might require splitting your stack into two separate stacks or using a nested stack approach.
The "InvalidRequest" error you encountered when trying to import the resource could be due to discrepancies between the actual resource and how you're defining it in CloudFormation. Make sure all properties match exactly, including any default values that might be set on the existing resource.
Remember that resource policies for CloudTrail EventDataStores are relatively new features, and there might be some limitations or quirks in how they interact with CloudFormation that aren't well documented yet. If these approaches don't work, you might need to reach out to AWS support for further assistance.
Sources
AWS::CloudTrail::ResourcePolicy - AWS CloudFormation
Getting started with AWS CloudTrail tutorials - AWS CloudTrail
AWS::CloudTrail::EventDataStore - AWS CloudFormation
answered 2 years ago
Hi,
From the error message that you get, it seems that you already have active policies on the resources for which you provide the ARN.
So, go to your CloudTrail console and check if you have some policies already active on those resources ARNs: you cannot have multiple such policies on 1 same resource defined by its ARN.
Best,
Didier
