Not able to import S3BucketOrigin from aws_cdk.aws_cloudfront_origins when using Python cdk api #31757
-
Even though in the documentation I can see that S3BucketOrigin is now the recommended way and S3Origin class is deprecated, I am not able to import and use S3BucketOrigin. Trying to use it like in the example below gives attribute error. I am not sure if this is not yet supported in Python or am I facing some issue with installing correct python packages. Can anybody please help me understand this issue? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @nikhil-salodkar , I tried to deploy the shared code with this configuration and it was deployed successfully- requirements.txt file-
Code - from aws_cdk import (
# Duration,
Stack,
# aws_sqs as sqs,
aws_s3 as s3,
aws_cloudfront as cloudfront,
aws_cloudfront_origins as origins
)
from constructs import Construct
class S3BucketOriginStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
my_bucket = s3.Bucket(self, "myBucket")
cloudfront.Distribution(self, "myDist",
default_behavior=cloudfront.BehaviorOptions(origin=origins.S3BucketOrigin.with_origin_access_control(my_bucket)) ) Synthesized template snippet - "myDistOrigin1S3OriginAccessControlE8B497E9": {
"Type": "AWS::CloudFront::OriginAccessControl",
"Properties": {
"OriginAccessControlConfig": {
"Name": "S3BucketOriginStackmyDistOrigin1S3OriginAccessControlF6E375AF",
"OriginAccessControlOriginType": "s3",
"SigningBehavior": "always",
"SigningProtocol": "sigv4"
}
},
"Metadata": {
"aws:cdk:path": "S3BucketOriginStack/myDist/Origin1/S3OriginAccessControl/Resource"
}
},
"myDist9DB766F3": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"DefaultCacheBehavior": {
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"Compress": true,
"TargetOriginId": "S3BucketOriginStackmyDistOrigin183C07BB1",
"ViewerProtocolPolicy": "allow-all"
},
"Enabled": true,
"HttpVersion": "http2",
"IPV6Enabled": true,
"Origins": [
{
"DomainName": {
"Fn::GetAtt": [
"myBucket5AF9C99B",
"RegionalDomainName"
]
},
"Id": "S3BucketOriginStackmyDistOrigin183C07BB1",
"OriginAccessControlId": {
"Fn::GetAtt": [
"myDistOrigin1S3OriginAccessControlE8B497E9",
"Id"
]
},
"S3OriginConfig": {
"OriginAccessIdentity": ""
}
}
]
}
}, Hope that would do the needful! let me know if you need further help! |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Hi @nikhil-salodkar , I tried to deploy the shared code with this configuration and it was deployed successfully-
requirements.txt file-
Code -