{ "AWSTemplateFormatVersion" : "2010-09-09", "Resources" : { "DynamoDBTable" : { "Type" : "AWS::DynamoDB::Table", "Properties" : { "AttributeDefinitions" : [ { "AttributeName" : "Artist", "AttributeType" : "S" }, { "AttributeName" : "SongTitle", "AttributeType" : "S" } ], "KeySchema" : [ { "AttributeName" : "Artist", "KeyType" : "HASH" }, { "AttributeName" : "SongTitle", "KeyType" : "RANGE" } ], "ProvisionedThroughput" : { "ReadCapacityUnits" : "5", "WriteCapacityUnits" : "5" }, "TableName" : "PrometheonMusic" } }, "LambdaExecutionRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": {"Service": ["lambda.amazonaws.com"]}, "Action": ["sts:AssumeRole"] }] }, "Path": "/", "Policies": [{ "PolicyName": "root", "PolicyDocument": { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": ["logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": ["dynamodb:*"], "Resource": "arn:aws:dynamodb:*:*:*" }] } }], "RoleName": "DynamoDBFullLambdaAccess" } }, "ListLambdaFunction": { "Type": "AWS::Lambda::Function", "Properties" : { "Code" : { "S3Bucket": "cloudassessments-lab-files", "S3Key": "aws/s3/s3_static_site/list.zip" }, "Description" : "The function to list data from DynamoDB", "FunctionName" : "list", "Handler" : "list.list", "Role" : { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] }, "Runtime" : "nodejs8.10" }, "DependsOn" : ["LambdaExecutionRole"] }, "GetLambdaFunction": { "Type": "AWS::Lambda::Function", "Properties" : { "Code" : { "S3Bucket": "cloudassessments-lab-files", "S3Key": "aws/s3/s3_static_site/get.zip" }, "Description" : "The function to get data from DynamoDB", "FunctionName" : "get", "Handler" : "get.get", "Role" : { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] }, "Runtime" : "nodejs8.10" }, "DependsOn" : ["LambdaExecutionRole"] }, "PrometheonApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { "Name": "prometheon", "Description": "API used for prometheon requests", "FailOnWarnings" : true } }, "LambdaFunctionPermissionGet": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:invokeFunction", "FunctionName": {"Fn::GetAtt": ["GetLambdaFunction", "Arn"]}, "Principal": "apigateway.amazonaws.com", "SourceArn": {"Fn::Join": ["", ["arn:aws:execute-api:", {"Ref": "AWS::Region"}, ":", {"Ref": "AWS::AccountId"}, ":", {"Ref": "PrometheonApi"}, "/*"] ]} } }, "LambdaFunctionPermissionList": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:invokeFunction", "FunctionName": {"Fn::GetAtt": ["ListLambdaFunction", "Arn"]}, "Principal": "apigateway.amazonaws.com", "SourceArn": {"Fn::Join": ["", ["arn:aws:execute-api:", {"Ref": "AWS::Region"}, ":", {"Ref": "AWS::AccountId"}, ":", {"Ref": "PrometheonApi"}, "/*"] ]} } }, "ApiDeployment": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": [ "ApiMethodList", "ApiMethodGet" ], "Properties": { "RestApiId": {"Ref": "PrometheonApi"}, "StageName": "dev" } }, "PrometheonApiResourceRoot": { "Type": "AWS::ApiGateway::Resource", "Properties": { "RestApiId": {"Ref": "PrometheonApi"}, "ParentId": {"Fn::GetAtt": ["PrometheonApi", "RootResourceId"]}, "PathPart": "prometheon" } }, "PrometheonApiResourceId": { "DependsOn": "PrometheonApiResourceRoot", "Type": "AWS::ApiGateway::Resource", "Properties": { "RestApiId": {"Ref": "PrometheonApi"}, "ParentId": { "Ref": "PrometheonApiResourceRoot"}, "PathPart": "id" } }, "ApiMethodList": { "DependsOn": "LambdaFunctionPermissionList", "Type": "AWS::ApiGateway::Method", "Properties": { "ResourceId": {"Ref": "PrometheonApiResourceRoot"}, "RestApiId": {"Ref": "PrometheonApi"}, "HttpMethod": "GET", "AuthorizationType": "NONE", "Integration": { "Type": "AWS_PROXY", "IntegrationHttpMethod": "POST", "Uri": {"Fn::Join" : ["", [ "arn:aws:apigateway:", {"Ref": "AWS::Region"}, ":lambda:path/2015-03-31/functions/", {"Fn::GetAtt": ["ListLambdaFunction", "Arn"]}, "/invocations" ] ]} } } }, "ApiMethodGet": { "DependsOn": "LambdaFunctionPermissionGet", "Type": "AWS::ApiGateway::Method", "Properties": { "ResourceId": {"Ref": "PrometheonApiResourceId"}, "RestApiId": {"Ref": "PrometheonApi"}, "HttpMethod": "GET", "AuthorizationType": "NONE", "Integration": { "Type": "AWS_PROXY", "IntegrationHttpMethod": "POST", "Uri": {"Fn::Join" : ["", [ "arn:aws:apigateway:", {"Ref": "AWS::Region"}, ":lambda:path/2015-03-31/functions/", {"Fn::GetAtt": ["GetLambdaFunction", "Arn"]}, "/invocations" ] ]} } } } } }