Cloud Custodian Policies not working for EC2 and S3

0 votes
I am trying to write Cloud custodian policies but I couldn't find a straight up rules filters for this in the official docs.

I am writing policies to terminate all internet facing ec2 instances and public S3 buckets.

Can someone help me as where am going wrong?
Oct 30, 2018 in AWS by findingbugs
• 3,260 points
517 views

2 answers to this question.

0 votes

You can refer to this documentation of AWS on: Cloud Custodian Docs

policies:
  - name: find-ec2-on-public-subnets
    resource: ec2
    filters:
        - type: value
          key: "SubnetId"
          op: in
          value:
              - subnet-d1e4xxxxx
              - subnet-d1e4xxxxx
    actions:
        - stop

  - name: s3-global-access
    resource: s3
    filters:
      - type: global-grants
    actions:
      - type: delete-global-grants
        grantees:
          - "http://acs.amazonaws.com/groups/global/AllUsers"
          - "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
answered Oct 30, 2018 by Priyaj
• 57,640 points
+1 vote

There are no straight up examples. Best to run a policy to capture resources of what you are looking for and build a filter based upon what you find in the resources.json file. Below is some sample code to get you started along your path. Try running the custodian policy with no filter defined, just the resource then look at the resources.json contents..

policies:

  - name: purge-lambda-after-7-days

    resource: lambda

    filters:

    - type: value

      value: ec2

      key: FunctionName

      value_type: normalize

     op: not_in

Example resources.json file;

[

  {

    "FunctionName": "EC2_Instance_Check",

answered Mar 1, 2019 by anonymous

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Attaching multiple policies for S3

As per the AWS documentation here, an ...READ MORE

answered Jul 30, 2019 in AWS by Praveen
• 700 points
522 views
+1 vote
1 answer

i have configure docker on AWS EC2 instance but commands are not working inside docker container.

Hello @Aniket , The docker exec command runs a new command ...READ MORE

answered Aug 5 in AWS by Niroj
• 58,500 points
92 views
0 votes
1 answer

How to transfer files between AWS s3 and AWS ec2?

Hi@akhtar, You can use the AWS CLI command to ...READ MORE

answered 4 days ago in AWS by MD
• 56,480 points
83 views
0 votes
1 answer