test
This commit is contained in:
parent
f23cc3c677
commit
a38cddf060
45
cloudfront.py
Normal file
45
cloudfront.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import boto3
|
||||||
|
import base64
|
||||||
|
import os
|
||||||
|
|
||||||
|
def create_cloudfront_distribution(cloudfront_client, bucket_name):
|
||||||
|
# Create CloudFront distribution for the S3 static website
|
||||||
|
response = cloudfront_client.create_distribution(
|
||||||
|
DistributionConfig={
|
||||||
|
'CallerReference': str(base64.b64encode(os.urandom(32))),
|
||||||
|
'Origins': {
|
||||||
|
'Items': [
|
||||||
|
{
|
||||||
|
'Id': bucket_name,
|
||||||
|
'DomainName': f'{bucket_name}.s3.amazonaws.com',
|
||||||
|
'S3OriginConfig': {
|
||||||
|
'OriginAccessIdentity': ''
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'Quantity': 1
|
||||||
|
},
|
||||||
|
'Enabled': True,
|
||||||
|
'DefaultCacheBehavior': {
|
||||||
|
'TargetOriginId': bucket_name,
|
||||||
|
'ViewerProtocolPolicy': 'redirect-to-https',
|
||||||
|
'AllowedMethods': {
|
||||||
|
'Items': ['GET', 'HEAD'],
|
||||||
|
'Quantity': 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'DefaultRootObject': 'index.html',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
distribution_id = response['Distribution']['Id']
|
||||||
|
distribution_domain = response['Distribution']['DomainName']
|
||||||
|
|
||||||
|
print(f"CloudFront distribution created with ID: {distribution_id}")
|
||||||
|
print(f"CloudFront URL: http://{distribution_domain}")
|
||||||
|
|
||||||
|
return distribution_domain
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cloudfront_client = boto3.client('cloudfront', region_name='us-east-1')
|
||||||
|
bucket_name = 's464863-bucket'
|
||||||
|
create_cloudfront_distribution(cloudfront_client, bucket_name)
|
4
cloudfront.sh
Normal file
4
cloudfront.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
chmod +x cloudfront.py
|
||||||
|
pip install boto3
|
||||||
|
python cloudfront.py
|
Loading…
Reference in New Issue
Block a user