By using AWS re:Post, you agree to the Terms of Use

Create or update Sagemaker Endpoint via CloudFormation


A wants to manage Sagemaker resources (such as models and endpoints) via CloudFormation. As part of their model deployment pipeline, they'd like to be able to create or update existing Sagemaker Endpoint with new model data. Customers wants to re-use the same endpoint name for a given workload.


How to express in CF a following logic:

  1. If Sagemaker endpoint with name "XYZ" doesn't exist in customer account, then create a new endpoint;
  2. If Sagemaker endpoint with name "XYZ" already exist, then update existing endpoint with new model data.
1 Answer
Accepted Answer

This functionality of "UPSERT" type does not exist in CFn natively. You would need to use a Custom Resource to handle this logic. One alternative that is not exactly what you asked for but might be a decent compromise is to use a Parameter to supply the endpoint if it does exist. Then use a condition to check the value. If the paramter is blank then create an endpoint if not use the value supplied. I know this is not what you asked for but it allows you to avoid the custom resource solution.

Sample of similiar UPSERT example for a VPC:

Parameters :

    Type: AWS::EC2::VPC::Id


  VpcNotSupplied: !Equals [!Ref Vpc, '']


    Type: AWS::EC2::VPC
    Condition: VpcNotSupplied

    Type: AWS::EC2::SecurityGroup
      GroupDescription: Sample
      GroupName: Sample
      VpcId: !If [VpcNotSupplied, !Ref NewVpc, !Ref Vpc ]

Here the Vpc input parameter can be supplied if the VPC you wish to use already exists, left blank if you want to create a new one. The NewVPC resource uses the Condition to only create if the supplied Vpc parameter value is blank. The Security group then uses the same condition to decide whetehr to use and existing Vpc or the newly created one.

Hope this makes sense.

profile picture
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions