text: {
    "AWSTemplateFormatVersion":"2010-09-09",
    "Description":"Mock a pipeline using CodePipeline and Lambda",
    "Parameters":{
      "S3Bucket":{
        "Type":"String",
        "Description":"S3 bucket to use for artifacts. Just bucket Name; not URL. IAM user should have access to the bucket.",
        "Default":"stelligent-training-public"
      },
      "S3Key":{
        "Type":"String",
        "Description":"S3 key within S3Bucket.",
        "Default":"public/codepipeline/aws-codepipeline-s3-aws-codedeploy_linux.zip"
      },
      "EmailAddress":{
        "Description":"Email Address",
        "Type":"String"
      }
    },
    "Resources":{
      "MySNSTopic":{
        "Type":"AWS::SNS::Topic",
        "Properties":{
          "Subscription":[
            {
              "Endpoint":{
                "Ref":"EmailAddress"
              },
              "Protocol":"email"
            }
          ]
        }
      },
      "LambdaCodePipelineExecutionPolicy":{
        "DependsOn":[
          "CodePipelineLambdaRole"
        ],
        "Type":"AWS::IAM::Policy",
        "Properties":{
          "PolicyName":"LambdaRolePolicy",
          "Roles":[
            {
              "Ref":"CodePipelineLambdaRole"
            }
          ],
          "PolicyDocument":{
            "Version":"2012-10-17",
            "Statement":[
              {
                "Effect":"Allow",
                "Action":[
                  "logs:*"
                ],
                "Resource":[
                  "arn:aws:logs:*:*:*"
                ]
              },
              {
                "Effect":"Allow",
                "Action":[
                  "codepipeline:PutJobSuccessResult",
                  "codepipeline:PutJobFailureResult"
                ],
                "Resource":[
                  "*"
                ]
              }
            ]
          }
        }
      },
      "CodePipelineLambdaRole":{
        "Type":"AWS::IAM::Role",
        "Properties":{
          "AssumeRolePolicyDocument":{
            "Version":"2012-10-17",
            "Statement":[
              {
                "Effect":"Allow",
                "Principal":{
                  "Service":[
                    "lambda.amazonaws.com"
                  ]
                },
                "Action":[
                  "sts:AssumeRole"
                ]
              }
            ]
          },
          "Path":"/"
        }
      },
      "CodePipelineLambdaDummy":{
        "Type":"AWS::Lambda::Function",
        "DependsOn":[
          "CodePipelineLambdaRole",
          "LambdaCodePipelineExecutionPolicy"
        ],
        "Properties":{
          "Code":{
            "S3Bucket":{
              "Ref":"S3Bucket"
            },
            "S3Key":"Archive.zip"
          },
          "Role":{
            "Fn::GetAtt":[
              "CodePipelineLambdaRole",
              "Arn"
            ]
          },
          "Description":"Always return success",
          "Timeout":20,
          "Handler":"lambdadummy.handler",
          "Runtime":"nodejs4.3",
          "MemorySize":128
        }
      },
      "CodePipelineStack":{
        "Type":"AWS::CodePipeline::Pipeline",
        "DependsOn":[
          "CodePipelineLambdaDummy"
        ],
        "Properties":{
          "RoleArn":{
            "Fn::Join":[
              "",
              [
                "arn:aws:iam::",
                {
                  "Ref":"AWS::AccountId"
                },
                ":role/AWS-CodePipeline-Service"
              ]
            ]
          },
          "Stages":[
            {
              "Name":"Source",
              "Actions":[
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"Source",
                  "ActionTypeId":{
                    "Category":"Source",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"S3"
                  },
                  "OutputArtifacts":[
                    {
                      "Name":"MyApp"
                    }
                  ],
                  "Configuration":{
                    "S3Bucket":{
                      "Ref":"S3Bucket"
                    },
                    "S3ObjectKey":{
                      "Ref":"S3Key"
                    }
                  },
                  "RunOrder":1
                }
              ]
            },
            {
              "Name":"Commit",
              "Actions":[
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"Build",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"UnitTest",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":2
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"StoreDistro",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":3
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"StaticAnalysis",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                }
              ]
            },
            {
              "Name":"AcceptanceTesting",
              "Actions":[
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"ProvisionEnvironment",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"InfrastructureAnalysis",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"ConfigureEnvironment",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":2
                },
                             {
                  "InputArtifacts":[
  
                  ],
                  "Name":"AcceptanceTests",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":3
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"IntegrationTests",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":3
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"DeployApp",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":4
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"DeploymentTest",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":5
                }
              ]
            },
            {
              "Name":"Capacity",
              "Actions":[
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"PenTest",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"PerformanceTest",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                },
                              {
                  "InputArtifacts":[
  
                  ],
                  "Name":"ImageTests",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"ResiliencyTests",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                }
              ]
            },
            {
              "Name":"ExploratoryTesting",
              "Actions":[
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"QA",
                  "ActionTypeId":{
                    "Category":"Approval",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Manual"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "NotificationArn":{
                      "Ref":"MySNSTopic"
                    },
                    "CustomData":"Approval or Reject this change after running Exploratory Tests"
                  },
                  "RunOrder":1
                }
              ]
            },
            {
              "Name":"Production",
              "Actions":[
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"BlueGreenDeployment",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"OutofBandTests",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"SecurityMetrics",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":1
                },
                {
                  "InputArtifacts":[
  
                  ],
                  "Name":"SwitchEndPoints",
                  "ActionTypeId":{
                    "Category":"Invoke",
                    "Owner":"AWS",
                    "Version":"1",
                    "Provider":"Lambda"
                  },
                  "OutputArtifacts":[
  
                  ],
                  "Configuration":{
                    "FunctionName":{
                      "Ref":"CodePipelineLambdaDummy"
                    },
                    "UserParameters":{
                      "Ref":"AWS::StackName"
                    }
                  },
                  "RunOrder":2
                }
              ]
            }
          ],
          "ArtifactStore":{
            "Type":"S3",
            "Location":{
              "Ref":"S3Bucket"
            }
          }
        }
      }
    },
    "Outputs":{
      "StackName":{
        "Value":{
          "Ref":"AWS::StackName"
        }
      },
      "CodePipelineURL":{
        "Value":{
          "Fn::Join":[
            "",
            [
              "https://console.aws.amazon.com/codepipeline/home?region=",
              {
                "Ref":"AWS::Region"
              },
              "#/view/",
              {
                "Ref":"CodePipelineStack"
              }
            ]
          ]
        }
      },
      "LambdaFunctionName":{
        "Value":{
          "Ref":"CodePipelineLambdaDummy"
        }
      }
    }
  }