Git Product home page Git Product logo

aws-asg-tags-lambda's Introduction

Released PreReleased CI Status license Swift 5.6

AWS Auto Scaling Groups Tag lambda

A lambda that add tags to the auto scaling groups of each k8s node.

You have to specify the cluster, the pools and the tags for each pool, or specify them in the common tags if you want the same tag for each node you want to process.

How to use

Push to AWS ECR

Our pipelines publish every new release to the docker hub, but in order to call it from a lambda, you have to push it to your AWS account private ECR.

Example (take into account that you can tag it with the name you want):

docker pull ydata/aws-asg-tags-lambda:1.0.0
docker tag ydata/aws-asg-tags-lambda:1.0.0 <your private ECR>/aws-asg-tags-lambda:1.0.0
docker push <your private ECR>/aws-asg-tags-lambda:1.0.0

CloudFormation

The execution role is necessary to connect to the EKS and EC2 for the auto scaling groups

ASGTagLambdaExecutionRole:
  Type: AWS::IAM::Role
  Properties:
    RoleName: !Join
      - '-'
        - 'role'
    AssumeRolePolicyDocument:
      Version: '2012-10-17'
      Statement:
      - Effect: Allow
        Principal:
          Service:
          - lambda.amazonaws.com
        Action:
        - sts:AssumeRole
    ManagedPolicyArns:
    - arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
    Policies:
    - PolicyName: !Join
        - '-'
          - 'lambda-asg-tag'
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
        - Effect: Allow
          Action:
          - eks:*
          - autoscaling:CreateOrUpdateTags
          Resource: '*'

The declaration of the lambda function, which will be used by the invoke

ASGTagLambdaFunction:
  Type: AWS::Lambda::Function
  Properties:
    Role: !GetAtt ASGTagLambdaExecutionRole.Arn
    PackageType: Image
    Code:
      ImageUri: !Ref EcrImageUri
    Architectures:
    - x86_64
    MemorySize: 1024
    Timeout: 300

The lambda invokation

ASGTagLambdaInvoke:
  Type: AWS::CloudFormation::CustomResource
  DependsOn: ASGTagLambdaFunction
  Version: "1.0"
  Properties:
    ServiceToken: !GetAtt ASGTagLambdaFunction.Arn
    StackID: !Ref AWS::StackId
    AccountID: !Ref AWS::AccountId
    Region: !Ref AWS::Region
    ClusterName: "the EKS cluster name" #!Ref EKSCluster
    CommonTags:
    - Name: "ENVIRONMENT"
      Value: "dev"
      PropagateAtLaunch: true
    NodePools:
    - Name: "system-nodepool" #!GetAtt YourNodeGroup.NodegroupName
      Tags:
      - Name: 'k8s.io/cluster-autoscaler/node-template/taint/TAINT'
        Value: 'TAINT_VALUE:TAINT_EFFECT'
        PropagateAtLaunch: true
      - Name: 'k8s.io/cluster-autoscaler/node-template/label/LABEL'
        Value: 'LABEL_VALUE'
        PropagateAtLaunch: true
    - Name: "another-pool"

Both CommonTags and Tags of each NodePool are optional, but if you don't specify CommonTags neither Tags for each NodePool, it will not do anything.

Check the following examples for other valid combinations

An example with only CommonTags

EKSASGTagLambdaInvoke:
  Type: AWS::CloudFormation::CustomResource
  DependsOn: EKSASGTagLambdaFunction
  Version: "1.0"
  Properties:
    ServiceToken: !GetAtt EKSASGTagLambdaFunction.Arn
    StackID: !Ref AWS::StackId
    AccountID: !Ref AWS::AccountId
    Region: !Ref AWS::Region
    ClusterName: "the EKS cluster name"
    CommonTags:
    - Name: "ENVIRONMENT"
      Value: "prod"
      PropagateAtLaunch: true
    NodePools:
    - Name: "system-nodepool"
    - Name: "applications-nodepool"

An example with only Tags for the NodePool

EKSASGTagLambdaInvoke:
  Type: AWS::CloudFormation::CustomResource
  DependsOn: EKSASGTagLambdaFunction
  Version: "1.0"
  Properties:
    ServiceToken: !GetAtt EKSASGTagLambdaFunction.Arn
    StackID: !Ref AWS::StackId
    AccountID: !Ref AWS::AccountId
    Region: !Ref AWS::Region
    ClusterName: "the EKS cluster name"
    NodePools:
    - Name: "system-nodepool"
      Tags:
      - Name: 'k8s.io/cluster-autoscaler/node-template/taint/TAINT'
        Value: 'TAINT_VALUE:NoSchedule'
        PropagateAtLaunch: true
      - Name: 'k8s.io/cluster-autoscaler/node-template/label/LABEL'
        Value: 'LABEL_VALUE'
        PropagateAtLaunch: true
    - Name: "application-nodepool"
      Tags:
      - Name: 'k8s.io/cluster-autoscaler/node-template/taint/TAINT'
        Value: 'TAINT_VALUE:NoSchedule'
        PropagateAtLaunch: true
      - Name: 'k8s.io/cluster-autoscaler/node-template/label/LABEL'
        Value: 'LABEL_VALUE'
        PropagateAtLaunch: true

TODO

  • Add generic context
  • Tests
  • Better Documentation
  • Support other methods of invocation

About ๐Ÿ‘ฏโ€โ™‚๏ธ

With โค๏ธ from YData Development team

aws-asg-tags-lambda's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

aws-asg-tags-lambda's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
command.Dockerfile
  • swift 5.7-jammy
  • swift 5.7-jammy-slim
lambda.Dockerfile
  • swift 5.7-bionic
  • swift 5.7-amazonlinux2-slim
github-actions
.github/workflows/merge-main.yml
  • actions/checkout v4
  • cycjimmy/semantic-release-action v3
  • actions/create-release v1
  • hugo19941994/delete-draft-releases v1.0.1
  • actions/create-release v1
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/prereleased.yml
  • ydataai/cancel-workflow-action 0.7.0-fix
  • actions/checkout v4
  • actions/cache v4
  • docker/build-push-action v5
  • anchore/sbom-action v0
  • aws-actions/configure-aws-credentials v4
  • docker/login-action v3
  • actions/checkout v4
  • actions/cache v4
  • docker/build-push-action v5
  • anchore/sbom-action v0
  • aws-actions/configure-aws-credentials v4
  • docker/login-action v3
  • actions/checkout v4
  • actions/checkout v4
  • anchore/sbom-action v0
  • aws-actions/configure-aws-credentials v4
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/pull-request.yml
  • ydataai/cancel-workflow-action 0.7.0
  • actions/checkout v4
  • actions/cache v4
  • fwal/setup-swift v2
  • actions/checkout v4
  • anchore/sbom-action v0
  • aws-actions/configure-aws-credentials v4
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/released.yml
  • ydataai/cancel-workflow-action 0.7.0-fix
  • actions/checkout v4
  • docker/login-action v3
  • docker/login-action v3
  • actions/checkout v4
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
swift
Package.swift
  • soto-project/soto from: "6.8.0"
  • swift-server/async-http-client from: "1.20.1"
  • apple/swift-argument-parser from: "1.3.1"

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.