Skip to content

Commit

Permalink
use new macros for deployment of cf template.
Browse files Browse the repository at this point in the history
  • Loading branch information
wparad committed May 26, 2019
1 parent 1685766 commit c68fbb3
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 381 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This is the changelog for [AWS Architect](readme.md).
## 6.2 ##
* Allow setting upload zip file directly to support creating lambda layers
* Add `publishZipArchive` to publish layers and other zip files directly to S3, using the package name and version automatically.
* New option in `publishLambdaArtifactPromise` to allow turning off running npm or yarn for package deployment `autoHandleCompileOfSourceDirectory = false`.

## 6.1 ##
* Deploy CF templates to S3 deployment bucket before deploying to CF to increase allow size of templates to 450KB.
Expand Down
147 changes: 28 additions & 119 deletions bin/template/cloudFormationHostedZoneTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,141 +6,50 @@
"Description": "The name of the new Hosted Zone to create"
}
},

"Transform": [
"AwsArchitectMacros"
],

"Resources": {
"CreateAndReturnAcmCertificateArnRole": {
"Type": "AWS::IAM::Role",
"HostedZone": {
"Type": "AWS::Route53::HostedZone",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": ["lambda.amazonaws.com"]
},
"Action": ["sts:AssumeRole"]
}]
"HostedZoneConfig": {
"Comment": "Dynamic Hosted Zone"
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
"arn:aws:iam::aws:policy/AWSCertificateManagerFullAccess"
]
"Name": { "Ref": "hostedZoneName" }
}
},
"CreateAndReturnAcmCertificateArnLambdaFunction": {
"Type": "AWS::Lambda::Function",

"AcmCertificateForHostedZone": {
"Type": "AWS::CertificateManager::Certificate",
"Properties": {
"FunctionName": {
"Fn::Join": [
"-",
[
{
"Fn::Join": [
"-",
{
"Fn::Split" : [
".",
{ "Ref": "hostedZoneName" }
]
}
]
},
"CertResolver"
]
"DomainName": { "Ref": "hostedZoneName" },
"SubjectAlternativeNames": [
{
"Fn::Sub": [
"*.${Domain}.",
{ "Domain": { "Ref": "hostedZoneName" } }
]
},
"Code": {
"ZipFile": {
"Fn::Join": [ "\n", [
"// http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html",
"const aws = require('aws-sdk');",
"const cloudFormationResponseHandler = require('cfn-response');",
"let acmClient = new aws.ACM();",
"exports.handler = function(event, context) {",
" let domainName = event.ResourceProperties.DomainName;",
" if (event.RequestType === 'Delete') {",
" return acmClient.listCertificates({}).promise()",
" .then(certs => {",
" let foundCert = certs.CertificateSummaryList.find(cert => cert.DomainName === domainName);",
" if (foundCert) {",
" console.log('Certificate Deleted', foundCert.CertificateArn);",
" return acmClient.deleteCertificate({ CertificateArn: foundCert.CertificateArn }).promise();",
" }",
" return null;",
" })",
" .then(() => {",
" return cloudFormationResponseHandler.send(event, context, cloudFormationResponseHandler.SUCCESS);",
" })",
" .catch(error => {",
" return cloudFormationResponseHandler.send(event, context, cloudFormationResponseHandler.FAILED, { title: 'Failed to delete Certificate', error: error });",
" });",
" }",
" ",
" if (event.RequestType !== 'Create') {",
" return cloudFormationResponseHandler.send(event, context, cloudFormationResponseHandler.SUCCESS);",
" }",
" ",
" return acmClient.requestCertificate({ DomainName: domainName, SubjectAlternativeNames: [`*.${domainName}`], ValidationMethod: 'DNS' }).promise()",
" .then(data => {",
" return new Promise(resolve => setTimeout(resolve, 20000))",
" .then(() => {",
" return acmClient.describeCertificate({ CertificateArn: data.CertificateArn }).promise()",
" .then(validationData => {",
" let response = {",
" CertificateArn: data.CertificateArn,",
" VerificationRecordName: validationData.Certificate.DomainValidationOptions[0].ResourceRecord.Name,",
" VerificationRecordValue: validationData.Certificate.DomainValidationOptions[0].ResourceRecord.Value",
" };",
" console.log('Certificate created', response);",
" return cloudFormationResponseHandler.send(event, context, cloudFormationResponseHandler.SUCCESS, response);",
" });",
" });",
" })",
" .catch(error => {",
" return cloudFormationResponseHandler.send(event, context, cloudFormationResponseHandler.FAILED, { title: 'Failed to created Certificate', error: error });",
" });",
"}"
]]
}
},
"Handler": "index.handler",
"Runtime": "nodejs6.10",
"Timeout": "30",
"Role": { "Fn::GetAtt": [ "CreateAndReturnAcmCertificateArnRole", "Arn" ] }
}
},
"AcmCertificateForHostedZone": {
"Type": "Custom::LambdaCallout",
"Properties": {
"ServiceToken": { "Fn::GetAtt": [ "CreateAndReturnAcmCertificateArnLambdaFunction", "Arn" ] },
"DomainName": { "Ref": "hostedZoneName" }
],
"ValidationMethod": "DNS"
}
},

"AcmCertificateValidationForHostedZone": {
"Type": "AWS::Route53::RecordSet",
"Type": "AwsArchitectResource::Route53DnsValidationRecord",
"Properties": {
"HostedZoneName": {
"Fn::Join": [
"",
[
{ "Ref": "hostedZoneName" },
"."
]
]
"Fn::Sub": [
"${Domain}.",
{ "Domain": { "Ref": "hostedZoneName" } }
]
},
"Name": { "Fn::GetAtt": [ "AcmCertificateForHostedZone", "VerificationRecordName" ] },
"ResourceRecords": [{ "Fn::GetAtt": [ "AcmCertificateForHostedZone", "VerificationRecordValue" ] }],
"CertificateArn": { "Ref": "AcmCertificateForHostedZone" },
"TTL": "300",
"Type": "CNAME"
},
"DependsOn": "AcmCertificateForHostedZone"
},
"HostedZone": {
"Type": "AWS::Route53::HostedZone",
"Properties": {
"HostedZoneConfig": {
"Comment": "Dynamic Hosted Zone"
},
"Name": { "Ref": "hostedZoneName" }
}
}
}
Expand Down
Loading

0 comments on commit c68fbb3

Please sign in to comment.