AWSTemplateFormatVersion: '2010-09-09'
Description: 'stack: {{stackName}} | deployed by Kes'
Parameters:
{{#each workflowLambdas}}
  {{@key}}LambdaFunction:
    Type: String
{{/each}}

Resources:
#################################################
# 'Old' Lambda Version/Alias block BEGIN
#################################################
{{#each oldLambdas}}
{{#if this.lambdaRefs}}
{{#each this.lambdaRefs}}
  {{@../key}}LambdaAlias{{this.hash}}:
    Type: AWS::Lambda::Alias
    Properties:
      Description: Cumulus AutoGenerated Alias |{{this.humanReadableIdentifier}}
      FunctionName: !Ref {{@../key}}LambdaFunction
      FunctionVersion: !GetAtt {{@../key}}LambdaVersion{{this.hash}}.Version
      Name: {{@../key}}-{{this.hash}}
  {{@../key}}LambdaVersion{{this.hash}}:
    Type: AWS::Lambda::Version
    Properties:
      FunctionName:
        !Ref {{@../key}}LambdaFunction
{{/each}}
{{/if}}
{{/each}}
#################################################
# 'Old' Lambda Version/Alias block END
#################################################

#################################################
# 'Current' Lambda Version/Alias block BEGIN
#################################################
{{#each workflowLambdas}}
{{#if this.hash}}
  {{@key}}LambdaAlias{{this.hash}}:
    Type: AWS::Lambda::Alias
    Properties:
      Description: Cumulus AutoGenerated Alias |{{this.humanReadableIdentifier}}
      FunctionName: !Ref {{@key}}LambdaFunction
      FunctionVersion: !GetAtt {{@key}}LambdaVersion{{this.hash}}.Version
      Name: {{@key}}-{{this.hash}}
  {{@key}}LambdaVersion{{this.hash}}:
    Type: AWS::Lambda::Version
    Properties:
      FunctionName:
        Ref: {{@key}}LambdaFunction
{{/if}}
{{/each}}
#################################################
# 'Current' Lambda Version/Alias block END
#################################################


#################################################
# Outputs block BEGIN
#################################################
Outputs:
{{#each workflowLambdas}}
{{#if this.hash}}
  {{@key}}LambdaAliasOutput:
    Value: !Ref {{@key}}LambdaAlias{{this.hash}}
{{/if}}
{{#unless this.hash}}
  {{@key}}LambdaAliasOutput:
    Value: 'No Value'
{{/unless}}
{{/each}}
################################################
# Outputs block END
#################################################
