This shows you the differences between two versions of the page.
| aws:lambda:letsencrypt_wildcard [2022/07/21 10:41] – created - external edit 127.0.0.1 | aws:lambda:letsencrypt_wildcard [2024/08/19 18:33] (current) – [Lambda Function Code] updating to use al2023 ami and correcting userdata variable formatting tingalls | ||
|---|---|---|---|
| Line 116: | Line 116: | ||
| client_ec2 = boto3.client(' | client_ec2 = boto3.client(' | ||
| client_sns = boto3.client(' | client_sns = boto3.client(' | ||
| - | amzn2_ami_parameter = '/ | + | |
| + | amzn2_ami_parameter = '/ | ||
| current_ami = client_ssm.get_parameter(Name=amzn2_ami_parameter)[' | current_ami = client_ssm.get_parameter(Name=amzn2_ami_parameter)[' | ||
| # | # | ||
| Line 134: | Line 135: | ||
| else: | else: | ||
| import_acm = ' | import_acm = ' | ||
| - | user_data = ''' | + | user_data = '''# |
| - | | + | sudo yum -y install python3 |
| - | sudo yum -y install python3 | + | sudo python3 -m ensurepip --upgrade |
| - | sudo python3 -m ensurepip --upgrade | + | python3 -m pip install certbot-route53 certbot-dns-cloudflare --user |
| - | python3 -m pip install certbot-route53 certbot-dns-cloudflare --user | + | #pip3 install certbot-route53 --user |
| - | #pip3 install certbot-route53 --user | + | AWS_DEFAULT_REGION=" |
| - | AWS_DEFAULT_REGION=" | + | DOMAINNAME=" |
| - | DOMAINNAME=" | + | echo " |
| - | echo " | + | CERTGENBUCKETNAME=" |
| - | CERTGENBUCKETNAME=" | + | SNSTOPICARN=" |
| - | SNSTOPICARN=" | + | IMPORT_ACM=" |
| - | IMPORT_ACM=" | + | CERT_REGION=" |
| - | CERT_REGION=" | + | echo " |
| - | echo " | + | if [[ $DNS_SERVICE == " |
| - | if [[ $DNS_SERVICE == " | + | echo "dns service is cloudflare" |
| - | echo "dns service is cloudflare" | + | echo " |
| - | echo " | + | chmod 600 / |
| - | chmod 600 / | + | / |
| - | / | + | fi |
| - | fi | + | if [[ $DNS_SERVICE == " |
| - | if [[ $DNS_SERVICE == " | + | echo "dns service is Route53" |
| - | echo "dns service is Route53" | + | / |
| - | / | + | fi |
| - | fi | + | ls -l / |
| - | ls -l / | + | P12PASSWORD=" |
| - | P12PASSWORD=" | + | openssl pkcs12 -export -inkey / |
| - | openssl pkcs12 -export -inkey / | + | ## To encrypt and backup certbot configuration |
| - | ## To encrypt and backup certbot configuration | + | # tar zcf - / |
| - | # tar zcf - / | + | ## To decrypt certbot configuration backup file |
| - | ## To decrypt certbot configuration backup file | + | # openssl enc -d -aes256 -in / |
| - | # openssl enc -d -aes256 -in / | + | aws --region $CERT_REGION ssm put-parameter --name / |
| - | aws --region $CERT_REGION ssm put-parameter --name / | + | aws --region $CERT_REGION s3 cp / |
| - | aws --region $CERT_REGION s3 cp / | + | ## To backup encrypted certbot configuration file |
| - | ## To backup encrypted certbot configuration file | + | # aws --region $CERT_REGION s3 cp / |
| - | # aws --region $CERT_REGION s3 cp / | + | if [[ $IMPORT_ACM == " |
| - | if [[ $IMPORT_ACM == " | + | CERT_ARN=$(aws --region $CERT_REGION acm list-certificates --query ' |
| - | CERT_ARN=$(aws --region $CERT_REGION acm list-certificates --query ' | + | echo $CERT_ARN |
| - | echo $CERT_ARN | + | if [[ $CERT_ARN != "" |
| - | if [[ $CERT_ARN != "" | + | echo " |
| - | echo " | + | aws --region $CERT_REGION acm import-certificate \ |
| - | aws --region $CERT_REGION acm import-certificate \ | + | |
| --certificate file:/// | --certificate file:/// | ||
| --private-key file:/// | --private-key file:/// | ||
| --certificate-chain file:/// | --certificate-chain file:/// | ||
| --certificate-arn $CERT_ARN >> / | --certificate-arn $CERT_ARN >> / | ||
| - | | + | |
| - | echo " | + | echo " |
| - | aws --region $CERT_REGION acm import-certificate \ | + | aws --region $CERT_REGION acm import-certificate \ |
| --certificate file:/// | --certificate file:/// | ||
| --private-key file:/// | --private-key file:/// | ||
| --certificate-chain file:/// | --certificate-chain file:/// | ||
| - | fi | ||
| fi | fi | ||
| - | | + | fi |
| - | aws --region us-east-1 sns publish --topic-arn $SNSTOPICARN --subject " | + | aws --region $CERT_REGION s3 cp / |
| - | sleep 60 | + | aws --region us-east-1 sns publish --topic-arn $SNSTOPICARN --subject " |
| - | sudo shutdown -h now | + | sleep 60 |
| + | sudo shutdown -h now | ||
| ''' | ''' | ||
| temp_instance_paramaters = { | temp_instance_paramaters = { | ||