Search code examples
amazon-web-servicesamazon-s3cloudcloudcustodian

Transferring Cloud Custodian output json file to S3


I have a requirement. I am using CloudCustodian to get resources metadata in dev environment. I created one sample policy.yml file for EC2 like below:

policies:
  - name: my-first-policy
    resource: ec2

When I run this command from a ec2:

custodian run --dryrun -s . policy.yml

I can see in the root directory one directory has been created with "my-first-policy". In this directory there is one file resource.json which includes all the details for EC2 instance. I want to send this file to s3 whenever I run cloud custodian command. How can I do this from command line?

Is there any policy that can be written which would transfer the resource.json file to S3 whenever I run the command?


Solution

  • You can supply the S3 bucket as a value to the -s / --output-dir argument

    custodian run --dryrun -s s3://mys3bucketpath policy.yml
    

    Then you can see the output stored in s3 directly

    aws s3 ls s3://mys3bucketpath
    

    References: