Skip to content

Instantly share code, notes, and snippets.

@d4goxn
Created May 9, 2016 15:58
Show Gist options
  • Save d4goxn/7322250ffe89f8a8a5c5d62804a8da2a to your computer and use it in GitHub Desktop.
Save d4goxn/7322250ffe89f8a8a5c5d62804a8da2a to your computer and use it in GitHub Desktop.
Serverless CloudFormation config for Elasticache Redis server
{
"name": "showConfig",
"runtime": "nodejs",
"description": "Returns Redis host and Serverless stage",
"handler": "redis/showConfig/handler.handler",
"timeout": 6,
"memorySize": 256,
"custom": {
"optimize": true
},
"environment": {
"STAGE": "${stage}",
"REDIS_HOST": "${redisHost}"
},
"endpoints": [{
"path": "redis/showConfig",
"method": "POST",
"type": "AWS",
"requestParameters": {},
"requestTemplates": "$${apiRequestTemplate}",
"responses": {
"default": {
"statusCode": "200"
}
}
}]
}
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "The AWS CloudFormation template for this Serverless application's resources outside of Lambdas and Api Gateway",
"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": "${stage}-${project}-lambda",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:${region}:*:*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface"
],
"Resource": "*"
}
]
},
"Roles": [
{
"Ref": "IamRoleLambda"
}
]
}
},
"RedisCluster" : {
"Type": "AWS::ElastiCache::CacheCluster",
"Properties": {
"CacheNodeType": "cache.t2.micro",
"CacheSecurityGroupNames": ["default"],
"Engine": "redis",
"NumCacheNodes": "1"
}
}
},
"Outputs": {
"IamRoleArnLambda": {
"Description": "ARN of the lambda IAM role",
"Value": {
"Fn::GetAtt": [
"IamRoleLambda",
"Arn"
]
}
},
"RedisHost": {
"Description": "ARN of the lambda IAM role",
"Value": {
"Fn::GetAtt": [
"RedisCluster",
"RedisEndpoint.Address"
]
}
}
}
}
@clstl
Copy link

clstl commented Jan 9, 2017

Did you manage to get it working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment