{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "The AWS CloudFormation template for this Serverless application",
  "Resources": {
    "ServerlessDeploymentBucket": {
      "Type": "AWS::S3::Bucket"
    },
    "HelloLogGroup": {
      "Type": "AWS::Logs::LogGroup",
      "Properties": {
        "LogGroupName": "/aws/lambda/plugin-test-dev-hello"
      }
    },
    "IamRoleLambdaExecution": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "lambda.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            }
          ]
        },
        "Policies": [
          {
            "PolicyName": {
              "Fn::Join": [
                "-",
                [
                  "dev",
                  "plugin-test",
                  "lambda"
                ]
              ]
            },
            "PolicyDocument": {
              "Version": "2012-10-17",
              "Statement": [
                {
                  "Effect": "Allow",
                  "Action": [
                    "logs:CreateLogStream"
                  ],
                  "Resource": [
                    {
                      "Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/plugin-test-dev-hello:*"
                    }
                  ]
                },
                {
                  "Effect": "Allow",
                  "Action": [
                    "logs:PutLogEvents"
                  ],
                  "Resource": [
                    {
                      "Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/plugin-test-dev-hello:*:*"
                    }
                  ]
                }
              ]
            }
          }
        ],
        "Path": "/",
        "RoleName": {
          "Fn::Join": [
            "-",
            [
              "plugin-test",
              "dev",
              "us-east-1",
              "lambdaRole"
            ]
          ]
        }
      }
    },
    "HelloLambdaFunction": {
      "Type": "AWS::Lambda::Function",
      "Properties": {
        "Code": {
          "S3Bucket": {
            "Ref": "ServerlessDeploymentBucket"
          },
          "S3Key": "serverless/plugin-test/dev/1554960564280-2019-04-11T05:29:24.280Z/plugin-test.zip"
        },
        "FunctionName": "plugin-test-dev-hello",
        "Handler": "handler.hello",
        "MemorySize": 1024,
        "Role": {
          "Fn::GetAtt": [
            "IamRoleLambdaExecution",
            "Arn"
          ]
        },
        "Runtime": "nodejs8.10",
        "Timeout": 6
      },
      "DependsOn": [
        "HelloLogGroup",
        "IamRoleLambdaExecution"
      ]
    },
    "HelloLambdaVersionQ2931VfBNMIcUBjZpdIoxHY0H1i0lJc0VfK87SxNj0I": {
      "Type": "AWS::Lambda::Version",
      "DeletionPolicy": "Retain",
      "Properties": {
        "FunctionName": {
          "Ref": "HelloLambdaFunction"
        },
        "CodeSha256": "jxWJ6zNyHCtBxzpfm4U9i1AouvWhXAfGwP6UOFdUNkA="
      }
    },
    "CICDRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "RoleName": "plugin-test-dev",
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "codepipeline.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            },
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "codebuild.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            }
          ]
        },
        "Policies": [
          {
            "PolicyName": "plugin-test-dev",
            "PolicyDocument": {
              "Version": "2012-10-17",
              "Statement": [
                {
                  "Effect": "Allow",
                  "Action": [
                    "elasticbeanstalk:*"
                  ],
                  "Resource": "*"
                }
              ]
            }
          }
        ]
      }
    },
    "Build": {
      "Type": "AWS::CodeBuild::Project",
      "Properties": {
        "Name": "plugin-test-dev",
        "ServiceRole": {
          "Fn::GetAtt": [
            "CICDRole",
            "Arn"
          ]
        },
        "Artifacts": {
          "Type": "CODEPIPELINE",
          "Name": "plugin-test-dev-build",
          "Packaging": "NONE"
        },
        "Environment": {
          "Type": "LINUX_CONTAINER",
          "ComputeType": "BUILD_GENERAL1_SMALL",
          "Image": "aws/codebuild/nodejs:6.3.1",
          "EnvironmentVariables": [
            {
              "Name": "STAGE",
              "Value": "dev"
            }
          ]
        },
        "Source": {
          "Type": "CODEPIPELINE"
        },
        "TimeoutInMinutes": 60
      }
    },
    "Pipeline": {
      "Type": "AWS::CodePipeline::Pipeline",
      "Properties": {
        "Name": "plugin-test-dev",
        "RoleArn": {
          "Fn::GetAtt": [
            "CICDRole",
            "Arn"
          ]
        },
        "Stages": [
          {
            "Name": "Source",
            "Actions": [
              {
                "Name": "Source",
                "ActionTypeId": {
                  "Category": "Source",
                  "Owner": "ThirdParty",
                  "Version": "1",
                  "Provider": "GitHub"
                },
                "OutputArtifacts": [
                  {
                    "Name": "plugin-test"
                  }
                ],
                "Configuration": {
                  "Owner": "KQED",
                  "Repo": "kqed-npr-one",
                  "Branch": "master",
                  "OAuthToken": "asdas"
                },
                "RunOrder": "1"
              }
            ]
          },
          {
            "Name": "Build",
            "Actions": [
              {
                "Name": "CodeBuild",
                "InputArtifacts": [
                  {
                    "Name": "plugin-test"
                  }
                ],
                "ActionTypeId": {
                  "Category": "Build",
                  "Owner": "AWS",
                  "Version": "1",
                  "Provider": "CodeBuild"
                },
                "OutputArtifacts": [
                  {
                    "Name": "plugin-testBuild"
                  }
                ],
                "Configuration": {
                  "ProjectName": {
                    "Ref": "Build"
                  }
                },
                "RunOrder": "1"
              }
            ]
          }
        ],
        "ArtifactStore": {
          "Type": "S3",
          "Location": {
            "Ref": "ServerlessDeploymentBucket"
          }
        }
      }
    }
  },
  "Outputs": {
    "ServerlessDeploymentBucketName": {
      "Value": {
        "Ref": "ServerlessDeploymentBucket"
      }
    },
    "HelloLambdaFunctionQualifiedArn": {
      "Description": "Current Lambda function version",
      "Value": {
        "Ref": "HelloLambdaVersionQ2931VfBNMIcUBjZpdIoxHY0H1i0lJc0VfK87SxNj0I"
      }
    }
  }
}