I am attempting to set a certificate in my CloudFrontDistribution using Cloud Formation.
My certificate has been issued via Certificate Manager. It has been approved, and I have validated that the certificate works by manual configuration directly through the CloudFront console.
Within my CloudFormation template, I have attempted to use both the Identifier and ARN values associated with the certificate in the IamCertificateId property:
"ViewerCertificate" : {
"IamCertificateId" : "********",
"SslSupportMethod": "sni-only"
}
But in both cases I receive the following error:
The specified SSL certificate doesn't exist, isn't valid, or doesn't include a valid certificate chain.
Reading the docs for the DistributionConfig Complex Type it looks like there is a 'ACMCertificateArn' property, but this does not seem to work via CloudFormation.
Any help would be appreciated.
Another valid approach I now use just creates the stack with the default certificate as long as the certificate is not issued (Inspired by this post)
It looks like
Took a few days but found the answer with some help from AWS support.
The information for:
is found using the CLI "aws iam list-server-certificates":
Once I found that I added a variable cloudfront.CloudFrontCertificateId with the ServerCertificateId and fed it into the ViewerCertificate:
(Update: As of Aug 9 2016, AWS CloudFormation now supports ACM using the
AcmCertificateArn
property, so the custom resource described below is no longer needed.)Although the AWS::CloudFront::Distribution resource hasn't been updated to support the ACMCertificateArn property yet, it is currently possible to use a custom CloudFormation resource to implement the functionality needed using the AWS API directly until the official resource is updated.
See Ryan S. Brown's post, CloudFormation To Build A CDN With (Free) Custom SSL where he describes his implementation of a
Custom::CloudFrontAcmAssociation
resource that associates an ACM certificate with a CloudFront distribution. The code is available atryansb/acm-certs-cloudformation
.To use it, you need to make the CloudFormation resource's implementation available through an AWS Lambda function. Ryan's implementation is already published to a public S3 bucket, so you can reference this directly for testing purposes in your CloudFormation template like so:
The
Lambda::Function
resource has a dependency on an IAM service Role and associated Policy to delegate the necessary permissions to the lambda function (theExecRole
reference above), so you need to add that too:With the lambda function in place, finally add the
Custom::CloudFrontAcmAssociation
resource, providing the distribution ID, certificate ARN, and the custom resource lambda function's ARN:tldr: copy all the code above into your CloudFormation template, set the appropriate
SiteCDN
andAcmCertificate
properties (or edit the template with hard-coded values), and you should have a custom resource workaround until Amazon updates the official CloudFront resource.I had a properly created certificate (public key 2048 bits), uploaded with the full chain. What was more challenging was the certificate was being used without problem in other AWS services (public ELB).
I was also passing the certificate Id (I had also tried with ARN but that's incorrect) correctly.
In my case, the problem was the certificate had been created with a "path": "/". After I uploaded a new certificate (with different name) with "Path": "/cloudfront/", everything worked without problem.
Cloudformation added this property but it is not documented. You can use like this easily:
Be aware that the certificate must be created in us-east-1 region, if not it won't be accepted.