Advertisement
gnomezgrave

Cloudformation template for SageMaker

Jul 4th, 2018
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.11 KB | None | 0 0
  1. Description: Creates the SageMaker model, endpoint config and the endpoint to expose the FIFA 18 prediction
  2.  
  3. Parameters:
  4.   Domain:
  5.     Description: Domain name
  6.     Type: String
  7.     Default: your_domain
  8.   Function:
  9.     Description: Function
  10.     Type: String
  11.     Default: your_function
  12.   Region:
  13.     Description: Region
  14.     Type: String
  15.     Default: your_region
  16.   AccountID:
  17.     Description: AWS Account ID
  18.     Type: String
  19.     Default: your_account_id
  20.   InstanceType:
  21.     Description: AWS Instance type for hosting the SageMaker model.
  22.     Type: String
  23.     Default: ml.m4.xlarge
  24.   S3Bucket:
  25.     Description: S3 Bucket Containing the custom model(s).
  26.     Type: String
  27.     Default: your_s3_bucket_name
  28.   ModelNamePrefix:
  29.     Description: Prefix for the model(s). This is useful in case we want to change the model naming convension
  30.     Type: String
  31.     Default: your_prefix
  32.   ModelVersion:
  33.     Description: Current version of the model
  34.     Type: String
  35.     Default: 1.0
  36.   Environment:
  37.     Type: String
  38.     Default: prod
  39.     Description: Define the environment
  40. Resources:
  41.   Endpoint:
  42.     Type: "AWS::SageMaker::Endpoint"
  43.     Properties:
  44.       EndpointName: !Sub ${Domain}--${Function}--predict-fifa-18-endpoint--${Environment}
  45.       EndpointConfigName:
  46.        !GetAtt EndpointConfig.EndpointConfigName
  47.       Tags:
  48.         - Key: Environment
  49.           Value: !Sub ${Environment}
  50.         - Key: Domain
  51.           Value: !Sub ${Domain}
  52.         - Key: Function
  53.           Value: !Sub ${Function}
  54.         - Key: Project
  55.           Value: !Sub ${Domain}
  56.   EndpointConfig:
  57.     Type: "AWS::SageMaker::EndpointConfig"
  58.     Properties:
  59.       EndpointConfigName: !Sub ${Domain}--${Function}--predict-fifa-18-endpoint-config--${Environment}
  60.       ProductionVariants:
  61.         - InitialInstanceCount: 1
  62.           InitialVariantWeight: 1.0
  63.           InstanceType: !Sub ${InstanceType}
  64.           ModelName: !GetAtt Model.ModelName
  65.           VariantName: !GetAtt Model.ModelName
  66.       Tags:
  67.         - Key: Environment
  68.           Value: !Sub ${Environment}
  69.         - Key: Domain
  70.           Value: !Sub ${Domain}
  71.         - Key: Function
  72.           Value: !Sub ${Function}
  73.         - Key: Project
  74.           Value: !Sub ${Domain}
  75.   Model:
  76.     Type: "AWS::SageMaker::Model"
  77.     Properties:
  78.       ModelName: !Sub ${Domain}--${Function}--predict-fifa-18-model--${Environment}
  79.       PrimaryContainer:
  80.         ModelDataUrl: !Sub "https://s3-${Region}.amazonaws.com/${S3Bucket}/models/${ModelNamePrefix}--v${ModelVersion}.hdf5.tar.gz"
  81.         Image: !Sub "${AccountID}.dkr.ecr.${Region}.amazonaws.com/your_ecr_image_id:${ModelVersion}"
  82.       ExecutionRoleArn: !GetAtt ExecutionRole.Arn
  83.       Tags:
  84.         - Key: Environment
  85.           Value: !Sub ${Environment}
  86.         - Key: Domain
  87.           Value: !Sub ${Domain}
  88.         - Key: Function
  89.           Value: !Sub ${Function}
  90.         - Key: Project
  91.           Value: !Sub ${Domain}
  92.  
  93.   ExecutionRole:
  94.     Type: "AWS::IAM::Role"
  95.     Properties:
  96.       RoleName: !Sub ${Domain}--${Function}--predict-fifa-18-role--${Environment}
  97.       ManagedPolicyArns:
  98.        - "arn:aws:iam::aws:policy/CloudWatchFullAccess"
  99.         - "arn:aws:iam::aws:policy/AmazonSageMakerFullAccess"
  100.       AssumeRolePolicyDocument:
  101.         Version: "2012-10-17"
  102.         Statement:
  103.           -
  104.             Effect: "Allow"
  105.             Principal:
  106.               Service:
  107.                 - "sagemaker.amazonaws.com"
  108.             Action:
  109.               - "sts:AssumeRole"
  110.       Path: "/"
  111.       Policies:
  112.         -
  113.           PolicyName: !Sub ${Domain}--${Function}--predict-fifa-18-policy--${Environment}
  114.           PolicyDocument:
  115.             Version: "2012-10-17"
  116.             Statement:
  117.             - Action:
  118.              - s3:ListBucket
  119.               Effect: Allow
  120.               Resource:
  121.              - !Sub arn:aws:s3:::${S3Bucket}
  122.             - Action:
  123.              - s3:GetObject
  124.               Effect: Allow
  125.               Resource:
  126.              - !Sub arn:aws:s3:::${S3Bucket}/*
  127. Outputs:
  128.   EndpointId:
  129.     Value: !Ref Endpoint
  130.   EndpointName:
  131.     Value: !GetAtt Endpoint.EndpointName
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement