Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
139 lines (123 sloc) 3.91 KB
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "The AWS CloudFormation template",
"Resources": {
"IamRoleLambda": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": [ "lambda.amazonaws.com" ] },
"Action": [ "sts:AssumeRole" ]
}]
},
"Path": "/"
}
},
"IamPolicyLambda": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": { "Fn::Join": [ "-", [ {"Ref": "AWS::StackName"}, "lambda" ] ] },
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ],
"Resource": { "Fn::Join": [ ":", [ "arn:aws:logs", { "Ref": "AWS::Region" }, "*:*"] ] }
}]
},
"Roles": [
{
"Ref": "IamRoleLambda"
}
]
}
},
"RestApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Name": { "Ref": "AWS::StackName" },
"Description": "A simple Api"
}
},
"HelloResource": {
"Type": "AWS::ApiGateway::Resource",
"Properties": {
"RestApiId": { "Ref": "RestApi" },
"ParentId": { "Fn::GetAtt": ["RestApi", "RootResourceId"] },
"PathPart": "hello"
}
},
"HelloGetMethod": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"RestApiId": { "Ref": "RestApi" },
"ResourceId": { "Ref": "HelloResource" },
"HttpMethod": "GET",
"AuthorizationType": "NONE",
"MethodResponses": [ { "StatusCode" : "200" }, { "StatusCode" : "400" } ],
"Integration": {
"Type": "AWS",
"IntegrationHttpMethod": "POST",
"IntegrationResponses": [
{ "StatusCode": "200", "ResponseTemplates": { "application/json": "$input.path('$')" } },
{ "StatusCode" : "400" }
],
"RequestTemplates" : {},
"Uri": { "Fn::Join" : ["", [
"arn:aws:apigateway:",
{"Ref": "AWS::Region"},
":lambda:path/2015-03-31/functions/",
{"Fn::GetAtt": ["HelloLambda", "Arn"]},
":prod",
"/invocations" ] ] }
}
}
},
"HelloAlias" : {
"Type" : "AWS::Lambda::Alias",
"DependsOn": ["HelloLambda"],
"Properties" : {
"Name": "prod",
"FunctionName": { "Fn::Join" : ["-", [ { "Ref": "AWS::StackName" }, "hello" ] ] },
"FunctionVersion": "$LATEST"
}
},
"HelloLambda": {
"Type": "AWS::Lambda::Function",
"Properties": {
"FunctionName": { "Fn::Join" : ["-", [ { "Ref": "AWS::StackName" }, "hello" ] ] },
"Handler": "index.handler",
"Role": { "Fn::GetAtt" : ["IamRoleLambda", "Arn"] },
"Code": { "ZipFile": "exports.handler = function(event, context, cb) { return cb(null, {message: 'Hello World'}); };" },
"Runtime": "nodejs4.3"
}
},
"LambdaInvokePermission": {
"Type": "AWS::Lambda::Permission",
"DependsOn": ["HelloLambda", "HelloAlias"],
"Properties": {
"FunctionName" : { "Fn::Join" : ["", [ { "Ref": "AWS::StackName" }, "-hello", ":prod" ] ] },
"Action": "lambda:InvokeFunction",
"Principal": "apigateway.amazonaws.com",
"SourceArn": {"Fn::Join" : ["", [
"arn:aws:execute-api", ":",
{ "Ref": "AWS::Region" }, ":",
{ "Ref": "AWS::AccountId" }, ":",
{ "Ref": "RestApi" },
"/*" ] ]
}
}
},
"ApiDeployment": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": ["HelloGetMethod"],
"Properties": {
"RestApiId": {"Ref": "RestApi"},
"StageName": "v1"
}
}
}
}