Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

150 lines (149 sloc) 5.51 KB
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Password Checker CFT Example",
"Parameters": {
"Password": {
"Default": "changethispassword",
"NoEcho": "true",
"Description": "what ever password you need",
"Type": "String",
"MinLength": "1",
"MaxLength": "41",
"AllowedPattern": "[a-zA-Z0-9]*",
"ConstraintDescription": "must contain only alphanumeric characters."
},
"ConfirmPassword": {
"Default": "changethispassword",
"NoEcho": "true",
"Description": "a confirmation of whatever password",
"Type": "String",
"MinLength": "1",
"MaxLength": "41",
"AllowedPattern": "[a-zA-Z0-9]*",
"ConstraintDescription": "must contain only alphanumeric characters."
}
},
"Metadata": {
"AWS::CloudFormation::Interface": {
"ParameterGroups": [
{
"Label": {
"default": "Testing the Password Confirmation Lambda"
},
"Parameters": [
"Password",
"ConfirmPassword"
]
}
]
}
},
"Resources": {
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Policies": [
{
"PolicyName": "lambdalogtocloudwatch",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
}
]
}
}
]
}
},
"CheckPasswordsFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": {
"Fn::Join": [
"\n",
[
"var response = require('cfn-response');",
"exports.handler = function(event, context) {",
" if (event.RequestType == 'Delete') {",
" response.send(event, context, response.SUCCESS);",
" return;",
" }",
" var password = event.ResourceProperties.Password;",
" var confpassword = event.ResourceProperties.ConfirmPassword;",
" var responseData = {};",
" if (password == confpassword) {",
" responseData = {'passwordcheck': 'Password Valid!'};",
" response.send(event, context, response.SUCCESS, responseData);",
" } else {",
" responseData = {Error: 'Passwords do not match'};",
" console.log(responseData.Error);",
" response.send(event, context, response.FAILED, responseData);",
" }",
"};"
]
]
}
},
"Handler": "index.handler",
"Runtime": "nodejs4.3",
"Timeout": "30",
"Role": {
"Fn::GetAtt": [
"LambdaExecutionRole",
"Arn"
]
}
}
},
"TestPasswords": {
"Type": "Custom::LambdaCallout",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"CheckPasswordsFunction",
"Arn"
]
},
"Password": {
"Ref": "Password"
},
"ConfirmPassword": {
"Ref": "ConfirmPassword"
}
}
}
},
"Outputs":{
"Results":{
"Description":"Test Passwords Result",
"Value":{
"Fn::GetAtt": [ "TestPasswords", "passwordcheck" ]
}
}
}
}
You can’t perform that action at this time.