Skip to content

Instantly share code, notes, and snippets.

@aletheia
Last active September 3, 2022 18:48
Show Gist options
  • Save aletheia/ad841ecf484b36c557a5c5a29987b814 to your computer and use it in GitHub Desktop.
Save aletheia/ad841ecf484b36c557a5c5a29987b814 to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
AWS Lambda Rust ML -- Example showing how to use Rust with AWS Lambda to build a customer churn predictor
Globals:
Function:
Resources:
S3ModelBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub
- 'lambda-rust-ml-model-bucket-${AccountID}'
- AccountID: !Ref AWS::AccountId
VersioningConfiguration:
Status: Enabled
CustomerDataStream:
Type: AWS::Kinesis::Stream
Properties:
ShardCount: 1
RetentionPeriodHours: 24
ResultQueue:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 300
CustomerChurnFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: target/lambda/aws-lambda-rust-ml
MemorySize: 128
Architectures: ["arm64"]
Handler: bootstrap
Runtime: provided.al2
Timeout: 5
Tracing: Active
Environment:
Variables:
RUST_LOG: info
S3_MODEL_LOCATION: !Ref S3ModelBucket
Events:
Stream:
Type: Kinesis
Properties:
Stream: !GetAtt CustomerDataStream.Arn
BatchSize: 100
StartingPosition: LATEST
Environment:
Variables:
STREAM_ARN: !Ref CustomerDataStream
QUEUE_ARN: !Ref ResultQueue
Policies:
- KinesisStreamReadPolicy :
StreamName: !Ref CustomerDataStream
- S3ReadPolicy:
BucketName: !Ref S3ModelBucket
Metadata:
BuildMethod: makefile
Outputs:
CustomerChurnFunction:
Description: "Customer Churn Prediction Function"
Value: !GetAtt CustomerChurnFunction.Arn
PutTable:
Description: "Customer Profile Data Stream"
Value: !GetAtt CustomerDataStream.Arn
@shinglyu
Copy link

Just in case the user wants to deploy this directly: add an AWS account ID to the end of the bucket name, otherwise the bucket name will not be unique.

@shinglyu
Copy link

Do we expect more lambda functions in the future? If not, simply move all the settings in the Global section into the function itself, so you don't need to explain what Global is.

@shinglyu
Copy link

Is it required to use an ARM CPU? What is the development platform you are going to use? An Apple M-series CPU? The cross-compilation might be a little tedious to explain.

@aletheia
Copy link
Author

aletheia commented Sep 3, 2022

Is it required to use an ARM CPU? What is the development platform you are going to use? An Apple M-series CPU? The cross-compilation might be a little tedious to explain.

I would like to use an ARM CPU to showcase Lambda cost reduction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment