It is possible to "deploy" new Lambda@Edge functions for CloudFront with CloudFormation.
CloudFront and Lambda@Edge requires versioned Lambda functions. So you need to make sure your CloudFront template publishes a new version on Lambda code changes, and that your Distribution uses the version alias.
See the CloudFormation template in my boilerplate Go/Lambda app for a working example:
WebAuthFunction:
Properties:
AutoPublishAlias: Live
CodeUri: ./web/handlers/auth/index.zip
Environment: !Ref AWS::NoValue
FunctionName: !Sub ${AWS::StackName}-WebAuthFunction
Handler: index.handler
Role: !GetAtt WebAuthFunctionRole.Arn
Runtime: nodejs6.10
Type: AWS::Serverless::Function
WebDistribution:
Condition: WebDomainNameSpecified
Properties:
DistributionConfig:
Aliases:
- !Ref WebDomainName
Comment: !Sub Distribution for ${WebBucket}
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
Compress: true
ForwardedValues:
Cookies:
Forward: none
QueryString: true
LambdaFunctionAssociations:
- !If
- OAuthClientIdSpecified
- EventType: viewer-request
LambdaFunctionARN: !Ref WebAuthFunction.Version
- !Ref AWS::NoValue
TargetOriginId: !Ref WebBucket
ViewerProtocolPolicy: redirect-to-https
DefaultRootObject: index.html
Enabled: true
HttpVersion: http2
Origins:
- DomainName: !Sub ${WebBucket}.s3.amazonaws.com
Id: !Ref WebBucket
S3OriginConfig:
OriginAccessIdentity: !Sub origin-access-identity/cloudfront/${WebOriginAccessIdentity}
PriceClass: PriceClass_All
ViewerCertificate:
AcmCertificateArn: !Ref WebCertificate
SslSupportMethod: sni-only
Type: AWS::CloudFront::Distribution