@@ -12,7 +12,7 @@ const getOriginConfig = (origin) => {
1212 }
1313
1414 if ( origin . includes ( 's3' ) ) {
15- const bucketName = origin . replace ( 'http ://' , '' ) . split ( '.' ) [ 0 ]
15+ const bucketName = origin . replace ( 'https ://' , '' ) . split ( '.' ) [ 0 ]
1616 originConfig . Id = bucketName
1717 originConfig . DomainName = `${ bucketName } .s3.amazonaws.com`
1818 }
@@ -97,7 +97,7 @@ const createCloudFrontDistribution = async (cf, inputs) => {
9797 return {
9898 id : res . Distribution . Id ,
9999 arn : res . Distribution . ARN ,
100- url : res . Distribution . DomainName
100+ url : `https:// ${ res . Distribution . DomainName } `
101101 }
102102}
103103
@@ -133,7 +133,27 @@ const updateCloudFrontDistribution = async (cf, distributionId, inputs) => {
133133 return {
134134 id : res . Distribution . Id ,
135135 arn : res . Distribution . ARN ,
136- url : res . Distribution . DomainName
136+ url : `https://${ res . Distribution . DomainName } `
137+ }
138+ }
139+
140+ const disableCloudFrontDistribution = async ( cf , distributionId ) => {
141+ const params = await cf . getDistributionConfig ( { Id : distributionId } ) . promise ( )
142+
143+ params . IfMatch = params . ETag
144+
145+ delete params . ETag
146+
147+ params . Id = distributionId
148+
149+ params . DistributionConfig . Enabled = false
150+
151+ const res = await cf . updateDistribution ( params ) . promise ( )
152+
153+ return {
154+ id : res . Distribution . Id ,
155+ arn : res . Distribution . ARN ,
156+ url : `https://${ res . Distribution . DomainName } `
137157 }
138158}
139159
@@ -144,7 +164,9 @@ const deleteCloudFrontDistribution = async (cf, distributionId) => {
144164 const params = { Id : distributionId , IfMatch : res . ETag }
145165 await cf . deleteDistribution ( params ) . promise ( )
146166 } catch ( e ) {
147- if ( e . code !== '' ) {
167+ if ( e . code === 'DistributionNotDisabled' ) {
168+ await disableCloudFrontDistribution ( cf , distributionId )
169+ } else {
148170 throw e
149171 }
150172 }
0 commit comments