-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding to work with others. not completed code. * acm-cert yaml test * working acm_cert upload * Added delete event to remove created ACM Added delete event to remove created ACM. Used SSM Parameter store to store the reference of ACM Arn. * ACM cert and ELB HTTPS * ACM selfsigned cert * ACMCertArn * added Fenix back * ACMCertARN as parameters * ACMCertARN update * removed Lambda for acm * Resolved review comments #369 - created logroup as cfn resource - created SSMParam as cfn resource - created self-signed cert with python lib - used OpenSSL lib (requires Lambda layer zip from S3 bucket). * lambda layer file for self sign cert * acm-cert-layer * ResourceBucket as pram * resource bucket as pram * Restricted SSM and ACM policy Restricted SSM and ACM policy for Lambda Execution role * Reverted aws-lambda-layer zip related changes. Used self-signed cert from RDS S3 bucket Co-authored-by: Ronak Shah <[email protected]> Co-authored-by: Ashish <[email protected]>
- Loading branch information
1 parent
9b3324e
commit 9b5195a
Showing
7 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
|
||
Description: > | ||
This template deploys the SSL/TLS selfsigned certificate for Retail Demo Store ELBs to ACM | ||
Author: Ronak Shah <[email protected]> | ||
Resources: | ||
ACMARNParameter: | ||
Type: AWS::SSM::Parameter | ||
Properties: | ||
Name: /retaildemostore/acm-arn | ||
Type: String | ||
Value: Dummy | ||
Description: Retail Demo Store ACM Arn | ||
|
||
ACMImportCertLambdaFunLogGroup: | ||
Type: AWS::Logs::LogGroup | ||
Properties: | ||
LogGroupName: !Sub /aws/lambda/${ACMimportCertLambdaFunction} | ||
RetentionInDays: 3 | ||
|
||
ACMimportCertLambdaFunction: | ||
Type: AWS::Lambda::Function | ||
DependsOn: ACMARNParameter | ||
Properties: | ||
Description: 'Retail Demo Store acm-import-certificate function that returns ARN for imported certificate' | ||
Code: | ||
ZipFile: | | ||
import boto3 | ||
import cfnresponse | ||
from botocore.exceptions import ClientError | ||
response_data = {} | ||
acm_client = boto3.client('acm') | ||
ssm_client = boto3.client('ssm') | ||
def handler(event, context): | ||
response_status = cfnresponse.SUCCESS | ||
acmarn_param_name = '/retaildemostore/acm-arn'; | ||
try: | ||
if event['RequestType'] == 'Create': | ||
# Get Self-Signed Certificate from retail-demo-store-code S3 bucket. | ||
s3 = boto3.resource('s3') | ||
obj = s3.Object('retail-demo-store-code', 'keys/test.cert') | ||
certifictate_pem = obj.get()['Body'].read() | ||
obj = s3.Object('retail-demo-store-code', 'keys/test.key') | ||
private_key_pem = obj.get()['Body'].read() | ||
my_response = acm_client.import_certificate( | ||
Certificate=certifictate_pem, | ||
PrivateKey=private_key_pem, | ||
Tags=[ | ||
{ | ||
'Key': 'ACM', | ||
'Value': 'retailDemoStore' | ||
}, | ||
] | ||
) | ||
# Overwrite Certificate ARN value in SSM Parameter | ||
acmarn_parameter = ssm_client.put_parameter( | ||
Name=acmarn_param_name, | ||
Value=my_response['CertificateArn'], | ||
Type='String', | ||
Overwrite=True) | ||
response_data['certificate_arn'] = my_response['CertificateArn'] | ||
response_data['Message'] = "Resource creation succeeded" | ||
elif event['RequestType'] == 'Update': | ||
response_data['Message'] = "Resource update succeeded" | ||
elif event['RequestType'] == 'Delete': | ||
# Delete the cert from ACM, assumes all attachments are already removed. | ||
# Retrieve ACM ARN from Parameter store | ||
acmarn_parameter = ssm_client.get_parameter(Name=acmarn_param_name) | ||
# Delete ACM | ||
my_response = acm_client.delete_certificate( | ||
CertificateArn=acmarn_parameter['Parameter']['Value'] | ||
) | ||
response_data['Message'] = "Resource deletion succeeded" | ||
except ClientError as e: | ||
print("Error: " + str(e)) | ||
response_status = cfnresponse.FAILED | ||
response_data['Message'] = "Resource {} failed: {}".format(event['RequestType'], e) | ||
cfnresponse.send(event, context, response_status, response_data) | ||
Handler: index.handler | ||
Runtime: python3.9 | ||
Timeout: 120 | ||
Role: !GetAtt ACMimportCertLambdaExecutionRole.Arn | ||
|
||
ACMimportCertLambdaExecutionRole: | ||
Type: 'AWS::IAM::Role' | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: 2012-10-17 | ||
Statement: | ||
- Effect: Allow | ||
Principal: | ||
Service: | ||
- lambda.amazonaws.com | ||
Action: | ||
- 'sts:AssumeRole' | ||
Path: / | ||
Policies: | ||
- PolicyName: CustomPolicy | ||
PolicyDocument: | ||
Version: 2012-10-17 | ||
Statement: | ||
- Effect: Allow | ||
Action: | ||
- logs:CreateLogStream | ||
- logs:DescribeLogStreams | ||
- logs:PutLogEvents | ||
Resource: | ||
- !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:*' | ||
- Effect: Allow | ||
Action: | ||
- ssm:GetParameter | ||
- ssm:PutParameter | ||
Resource: | ||
- !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/retaildemostore/acm-arn' | ||
- Effect: Allow | ||
Action: | ||
- acm:ImportCertificate | ||
- acm:DeleteCertificate | ||
- acm:AddTagsToCertificate | ||
Resource: | ||
- !Sub 'arn:aws:acm:${AWS::Region}:${AWS::AccountId}:certificate/*' | ||
- Effect: Allow | ||
Action: | ||
- s3:GetObject | ||
Resource: 'arn:aws:s3:::retail-demo-store-code/keys/*' | ||
ACMimportCertLambdaFunctionExecution: | ||
Type: Custom::CustomLambdaACMCert | ||
Version: "1.0" | ||
Properties: | ||
ServiceToken: !GetAtt ACMimportCertLambdaFunction.Arn | ||
|
||
Outputs: | ||
ACMimportCertLambdaFunctionArn: | ||
Description: Lambda function ARN for ACM self-signed cert function | ||
Value: !GetAtt ACMimportCertLambdaFunction.Arn | ||
ACMimportCertArn: | ||
Description: ACM self signed cert Arn to use in ELB listener | ||
Value: !GetAtt ACMimportCertLambdaFunctionExecution.certificate_arn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters