containers-roadmap icon indicating copy to clipboard operation
containers-roadmap copied to clipboard

[EKS] [request]: Create a notification for new versions of the EKS Optimized AMI

Open jicowan opened this issue 5 years ago • 24 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Tell us about your request What do you want us to build? Create an SNS topic for notifying customer when a new version of the EKS Optimized AMI is available.

Which service(s) is this request for? EKS

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard? What outcome are you trying to achieve, ultimately, and why is it hard/impossible to do right now? What is the impact of not having this problem solved? The more details you can provide, the better we'll be able to understand and solve the problem. Today, you have to call an API to upgrade the worker nodes in a managed node group. A notification would tell customer when a new version is available for upgrade.

Are you currently working around this issue? How are you currently solving this problem? Customers can monitor the GitHub repository, e.g. https://help.github.com/en/github/receiving-notifications-about-activity-on-github/watching-and-unwatching-releases-for-a-repository.

Additional context Anything else we should know?

Attachments If you think you might have additional information that you'd like to include via an attachment, please do - we'll take a look. (Remember to remove any personally-identifiable information.)

jicowan avatar Feb 04 '20 22:02 jicowan

@jicowan do you imagine this is just a notification or also includes some sort of metadata about the status of the AMI (tests passing, etc...)?

tabern avatar Mar 02 '20 03:03 tabern

When the image has been published and is ready for consumption. If the message includes metadata, it should include the AMI version/region, and SSM path.

jicowan avatar Mar 02 '20 18:03 jicowan

+1

arun-krishnakumar avatar Mar 11 '20 11:03 arun-krishnakumar

ECS has had this functionality since 2017 - https://aws.amazon.com/about-aws/whats-new/2017/03/introducing-notifications-for-new-amazon-ecs-optimized-ami-releases/. Can that implementation be leveraged for this need?

philm avatar Nov 17 '20 02:11 philm

We are waiting for this feature to automate our AMI upgrade story. After the SNS feature has been launched by EKS, is there a way to get notified only after a new version has been released globally?

jayackri avatar Jan 22 '21 22:01 jayackri

I have worked around this by having a CloudWatch Event rule invoke a lambda function that checks the eks-optimized ami SSM Parameters and save the last value per k8s version in a Dynamo DB table.

ryanpflynn avatar Feb 18 '21 17:02 ryanpflynn

Until AWS enables this feature natively . How about a mini Infrastructure as code package ( pulumi) that can create

  1. SNS topic
  2. Daily Lambda to check for new versions
  3. Post to SNS if there is a new Version If there is a enough interest I can work on this. Also would be nice to collaborate with someone

bit-cloner avatar Apr 21 '21 09:04 bit-cloner

For anyone interested. I made a sample Cloudformation template that can be deployed into the same region as the EKS cluster.

The template below has only two parameters required that are self explanatory:

CLUSTER => The Cluster name to search for managed node groups. (All node groups there will be updated) RATE => The rate that you want the update version call to be made.

The method is idempotent and can be executed safely:

1. If there are no AMI updates the node group will remain in the same version without disruption. 2. If there are updates, the flow will follow the update config specified and the nodes will be taken one at a time.

The usage:

1. Navigate to Cloudformation Console.
2. Upload the template attached (template.yaml).
3. Change the Cluster name and Rate as needed.
4. Deploy it.

The YAML template:

AWSTemplateFormatVersion: '2010-09-09'
Description: Lambda function to update Managed Node Groups for a given cluster based on a specific interval.
Parameters:

  CLUSTER:
    Type: String
    Default: efs
    Description: The Cluster name to search for Managed Node Groups

  REGION:
    Type: String
    Default: eu-central-1
    Description: The Cluster region

  RATE:
    Description: >
      The rate (frequency) that determines when CloudWatch Events runs the rule that
      triggers the Lambda function.
    Default: rate(10 minutes)
    AllowedValues:
      - rate(10 minutes)
      - rate(1 day)
      - rate(7 days)
      - rate(30 days)
    Type: String

Resources:

  LambdaSchedule:
    Type: "AWS::Events::Rule"
    Properties:
      Description: >
        A schedule for the Lambda function..
      ScheduleExpression: !Ref RATE
      State: ENABLED
      Targets:
        - Arn: !Sub ${UpdateFunction.Arn}
          Id: LambdaSchedule

  LambdaSchedulePermission:
    Type: "AWS::Lambda::Permission"
    Properties:
      Action: 'lambda:InvokeFunction'
      FunctionName: !Sub ${UpdateFunction.Arn}
      Principal: 'events.amazonaws.com'
      SourceArn: !Sub ${LambdaSchedule.Arn}

  UpdateFunction:
    Type: AWS::Lambda::Function
    Properties:
      Runtime: python3.8
      Role: !GetAtt LambdaExecutionRole.Arn
      Handler: index.handler
      Environment:
        Variables:
          cluster: !Ref CLUSTER
          region: !Ref REGION
      Code:
        ZipFile: |
          from __future__ import print_function
          import os
          import boto3

          client = boto3.client('eks')

          def handler(event, context):
              cluster = os.getenv("cluster", None)
              region = os.getenv("region", None)

              if cluster and region:
                  message = "Env vars are there cluster: {} region: {}!".format(cluster, region)
                  # List Node Groups inside cluster
                  response = client.list_nodegroups(
                      clusterName=cluster,
                  )
                  try:
                      for nodegroup in response['nodegroups']:
                          print("Node Group => {}".format(nodegroup))
                          response = client.update_nodegroup_version(
                              clusterName=cluster,
                              nodegroupName=nodegroup,
                          )
                          message = "Update => {}".format(response)
                  except:
                      message = "Something went badly wrong, do you have Managed Node groups in this cluster?"
              else:
                  message = "No env vars passed"

              print(message)
              return message
      Description: The function that perform the API Update call

  LambdaExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
        - Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
          Action:
          - sts:AssumeRole
      Path: "/"
      Policies:
      - PolicyName: root
        PolicyDocument:
          Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Action: '*'
              Resource: '*'

cchostak avatar Aug 13 '21 11:08 cchostak

Noticed the AMI notifications for ECS Optimized Linux AMI have not been working and it has been removed from documentation. Does this mean we wont be getting notifications from EKS and ECS AMI updates anymore?

https://github.com/awsdocs/amazon-ecs-developer-guide/commit/1114647d1722fdb796cea68f680b00e19439fbbd#diff-1734817e93fc2d78797cccf296458d94aee95fa6b8083b602b36d629020acfdb

doc_source/ECS-AMI-SubscribeTopic.md

v4de avatar Oct 04 '21 14:10 v4de

SNS Topic for ECS linux was deprecated when ECS optimized linux 1 ami was depreacted. So only option is to query ssm for now. Guess i'm making my own Lambda to check versions and update.

https://github.com/awsdocs/amazon-ecs-developer-guide/issues/184

v4de avatar Oct 04 '21 16:10 v4de

We also have a requirement to notify the customers about the new EKS AMI availability so that customers can update the CF stack to update the managed node groups. By when are we planning to release this feature?

amitkatyal avatar Oct 28 '21 13:10 amitkatyal

We've solved the problem of getting notified when a new AMI for the clusters we have is available by creating a custom lambda that checks the current image used by the nodes and the latest image of the same Kubernetes version, sending a message to a specific SNS topic.

But now, we're trying to solve a different problem that is getting notified when a new version of EKS (Kubernetes) is available, but I'm having a lot of issues because I can't find a way to retrieve the available versions or the latest version of Kubernetes in EKS (in a programmatic way). Any suggestion here?

ispirals avatar Oct 28 '21 15:10 ispirals

We've solved the problem of getting notified when a new AMI for the clusters we have is available by creating a custom lambda that checks the current image used by the nodes and the latest image of the same Kubernetes version, sending a message to a specific SNS topic.

But now, we're trying to solve a different problem that is getting notified when a new version of EKS (Kubernetes) is available, but I'm having a lot of issues because I can't find a way to retrieve the available versions or the latest version of Kubernetes in EKS (in a programmatic way). Any suggestion here?

Hi isprials, can you share the lambda code with me?

Aventuz avatar Oct 31 '21 14:10 Aventuz

We've solved the problem of getting notified when a new AMI for the clusters we have is available by creating a custom lambda that checks the current image used by the nodes and the latest image of the same Kubernetes version, sending a message to a specific SNS topic.

But now, we're trying to solve a different problem that is getting notified when a new version of EKS (Kubernetes) is available, but I'm having a lot of issues because I can't find a way to retrieve the available versions or the latest version of Kubernetes in EKS (in a programmatic way). Any suggestion here?

Hello isprials, can you please share the lambda code in the thread or directly with me, that would be helpful. Thanks in advance

anithreddy95 avatar Nov 03 '21 22:11 anithreddy95

This issue doesn't specify, but please don't forget about Bottlerocket.

This aws-cli command will return the latest x86-64 Bottlerocket AMI for EKS 1.21 in us-east-1.

aws --region us-east-1 ssm get-parameter \
  --name /aws/service/bottlerocket/aws-k8s-1.21/x86_64/latest/image_id \
  --query "Parameter.Value"

And this oneliner should print the AMI id to stdout if and only if it hasn't seen it before. Writes it to /tmp/eks-amis the first time it gets a new id. For the three people out there who still get emails from cron jobs it can be a quick and dirty solution.

aws --region us-east-1 ssm get-parameter \
    --name /aws/service/bottlerocket/aws-k8s-1.20/x86_64/latest/image_id \
    --query "Parameter.Value" --output text \
  | grep -v -f /tmp/eks-amis \
  | tee -a /tmp/eks-amis

bgdnlp avatar Apr 01 '22 06:04 bgdnlp

One more workaround...

AWS EKS AMI provides RSS about new releases: https://github.com/awslabs/amazon-eks-ami/releases.atom You can subscribe RSS feed eg. in Slack: https://slack.com/help/articles/218688467-Add-RSS-feeds-to-Slack

ad-m-ss avatar Apr 25 '22 03:04 ad-m-ss

Any update on when this feature would be available?

prashil-g avatar May 18 '22 10:05 prashil-g

This will be good to have

rohitgujral16 avatar May 26 '22 06:05 rohitgujral16

customers eagerly waiting for this. Please expedite.

singhnix avatar Dec 13 '22 06:12 singhnix

customers eagerly waiting for this. Please expedite.

There's always customers waiting for everything. Thumbs up the issue and the maintainers can quantify how many ppl care about each issue.

smiller171 avatar Dec 13 '22 15:12 smiller171

We've solved the problem of getting notified when a new AMI for the clusters we have is available by creating a custom lambda that checks the current image used by the nodes and the latest image of the same Kubernetes version, sending a message to a specific SNS topic.

But now, we're trying to solve a different problem that is getting notified when a new version of EKS (Kubernetes) is available, but I'm having a lot of issues because I can't find a way to retrieve the available versions or the latest version of Kubernetes in EKS (in a programmatic way). Any suggestion here?

@ispirals can you share the lambda? that would be very helpful

nan008 avatar Mar 28 '23 11:03 nan008

We created a terraform module to solve this problem and to allow for tracking and eventing on any publicly available AMIs. It is available below.

https://github.com/Evernorth/aws-ami-tracker

lafferrs avatar Dec 18 '23 16:12 lafferrs

Can this be prioritized please.

PRYeswanthReddy avatar Mar 05 '24 03:03 PRYeswanthReddy

One more workaround...

AWS EKS AMI provides RSS about new releases: https://github.com/awslabs/amazon-eks-ami/releases.atom You can subscribe RSS feed eg. in Slack: https://slack.com/help/articles/218688467-Add-RSS-feeds-to-Slack

This is a decent option but includes pre-release notifications as well..

tylergohl avatar Apr 10 '24 13:04 tylergohl

I am trying to get notifications regarding updates pending or new updates on AWS console. Can you please guide me how can we achieve using SNS and Lambda?

smanavi-NS1 avatar Jul 24 '24 14:07 smanavi-NS1