Skip to content

Conversation

@boutetnico
Copy link
Contributor

@boutetnico boutetnico commented Oct 13, 2025

SUMMARY

This PR adds a new module cloudfront_function to manage AWS CloudFront Functions.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

cloudfront_function

ADDITIONAL INFORMATION

CI currently fails because it requires IAM permissions to manage CloudFront functions:

Task failed: Module failed: An error occurred (AccessDenied) when calling the DescribeFunction operation

Waiting for this PR to be merged: mattclay/aws-terminator#323.

Example Usage:

# Create a function with inline code
- name: Create CloudFront function for redirects
  community.aws.cloudfront_function:
    name: redirect-function
    state: present
    comment: "Redirects HTTP to HTTPS"
    runtime: cloudfront-js-2.0
    code: |
      function handler(event) {
        var request = event.request;
        if (request.headers['cloudfront-viewer-protocol'][0].value === 'http') {
          return {
            statusCode: 301,
            statusDescription: 'Moved Permanently',
            headers: {
              'location': { value: 'https://' + request.headers.host[0].value + request.uri }
            }
          };
        }
        return request;
      }

# Load code from file and publish to LIVE
- name: Create and publish function from file
  community.aws.cloudfront_function:
    name: security-headers
    state: published
    comment: "Add security headers to responses"
    runtime: cloudfront-js-2.0
    code: "{{ lookup('file', 'cloudfront_functions/security-headers.js') }}"

# Update existing function
- name: Update function code
  community.aws.cloudfront_function:
    name: security-headers
    state: published
    comment: "Updated security headers"
    runtime: cloudfront-js-2.0
    code: "{{ lookup('file', 'cloudfront_functions/security-headers-v2.js') }}"

# Delete function
- name: Remove CloudFront function
  community.aws.cloudfront_function:
    name: old-function
    state: absent

@github-actions
Copy link

github-actions bot commented Oct 13, 2025

Docs Build 📝

Thank you for contribution!✨

The docsite for this PR is available for download as an artifact from this run:
https://github.com/ansible-collections/community.aws/actions/runs/18462431527

You can compare to the docs for the main branch here:
https://ansible-collections.github.io/community.aws/branch/main

File changes:

  • A collections/community/aws/cloudfront_function_module.html
  • M collections/community/aws/cloudfront_distribution_info_module.html
  • M collections/community/aws/cloudfront_invalidation_module.html
  • M collections/community/aws/index.html
  • M collections/index_module.html
Click to see the diff comparison.

NOTE: only file modifications are shown here. New and deleted files are excluded.
See the file list and check the published docs to see those files.

diff --git a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/cloudfront_distribution_info_module.html b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/cloudfront_distribution_info_module.html
index 5013eef..7ae6ed4 100644
--- a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/cloudfront_distribution_info_module.html
+++ b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/cloudfront_distribution_info_module.html
@@ -22,7 +22,7 @@
       <script src="../../../_static/sphinx_highlight.js?v=dc90522c"></script>
     <script src="../../../_static/js/theme.js"></script>
     <link rel="search" title="Search" href="../../../search.html" />
-    <link rel="next" title="community.aws.cloudfront_invalidation module – create invalidations for AWS CloudFront distributions" href="cloudfront_invalidation_module.html" />
+    <link rel="next" title="community.aws.cloudfront_function module – Manage AWS CloudFront Functions" href="cloudfront_function_module.html" />
     <link rel="prev" title="community.aws.cloudfront_distribution module – Create, update and delete AWS CloudFront distributions" href="cloudfront_distribution_module.html" /><!-- extra head elements for Ansible beyond RTD Sphinx Theme -->
 
 
@@ -671,7 +671,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-cloud
 
 <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
         <a href="cloudfront_distribution_module.html" class="btn btn-neutral float-left" title="community.aws.cloudfront_distribution module – Create, update and delete AWS CloudFront distributions" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
-        <a href="cloudfront_invalidation_module.html" class="btn btn-neutral float-right" title="community.aws.cloudfront_invalidation module – create invalidations for AWS CloudFront distributions" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
+        <a href="cloudfront_function_module.html" class="btn btn-neutral float-right" title="community.aws.cloudfront_function module – Manage AWS CloudFront Functions" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
     </div>
 
   <hr/>
diff --git a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/cloudfront_invalidation_module.html b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/cloudfront_invalidation_module.html
index 32bd71b..b61a692 100644
--- a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/cloudfront_invalidation_module.html
+++ b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/cloudfront_invalidation_module.html
@@ -23,7 +23,7 @@
     <script src="../../../_static/js/theme.js"></script>
     <link rel="search" title="Search" href="../../../search.html" />
     <link rel="next" title="community.aws.cloudfront_origin_access_identity module – Create, update and delete origin access identities for a CloudFront distribution" href="cloudfront_origin_access_identity_module.html" />
-    <link rel="prev" title="community.aws.cloudfront_distribution_info module – Obtain facts about an AWS CloudFront distribution" href="cloudfront_distribution_info_module.html" /><!-- extra head elements for Ansible beyond RTD Sphinx Theme -->
+    <link rel="prev" title="community.aws.cloudfront_function module – Manage AWS CloudFront Functions" href="cloudfront_function_module.html" /><!-- extra head elements for Ansible beyond RTD Sphinx Theme -->
 
 
 
@@ -480,7 +480,7 @@ see <a class="reference internal" href="#ansible-collections-community-aws-cloud
           
 
 <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
-        <a href="cloudfront_distribution_info_module.html" class="btn btn-neutral float-left" title="community.aws.cloudfront_distribution_info module – Obtain facts about an AWS CloudFront distribution" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
+        <a href="cloudfront_function_module.html" class="btn btn-neutral float-left" title="community.aws.cloudfront_function module – Manage AWS CloudFront Functions" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
         <a href="cloudfront_origin_access_identity_module.html" class="btn btn-neutral float-right" title="community.aws.cloudfront_origin_access_identity module – Create, update and delete origin access identities for a CloudFront distribution" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
     </div>
 
diff --git a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/index.html b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/index.html
index 75011d0..bed01ab 100644
--- a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/community/aws/index.html
+++ b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/community/aws/index.html
@@ -199,6 +199,7 @@
 <li><p><a class="reference internal" href="cloudformation_stack_set_module.html#ansible-collections-community-aws-cloudformation-stack-set-module"><span class="std std-ref">cloudformation_stack_set module</span></a> – Manage groups of CloudFormation stacks</p></li>
 <li><p><a class="reference internal" href="cloudfront_distribution_module.html#ansible-collections-community-aws-cloudfront-distribution-module"><span class="std std-ref">cloudfront_distribution module</span></a> – Create, update and delete AWS CloudFront distributions</p></li>
 <li><p><a class="reference internal" href="cloudfront_distribution_info_module.html#ansible-collections-community-aws-cloudfront-distribution-info-module"><span class="std std-ref">cloudfront_distribution_info module</span></a> – Obtain facts about an AWS CloudFront distribution</p></li>
+<li><p><a class="reference internal" href="cloudfront_function_module.html#ansible-collections-community-aws-cloudfront-function-module"><span class="std std-ref">cloudfront_function module</span></a> – Manage AWS CloudFront Functions</p></li>
 <li><p><a class="reference internal" href="cloudfront_invalidation_module.html#ansible-collections-community-aws-cloudfront-invalidation-module"><span class="std std-ref">cloudfront_invalidation module</span></a> – create invalidations for AWS CloudFront distributions</p></li>
 <li><p><a class="reference internal" href="cloudfront_origin_access_identity_module.html#ansible-collections-community-aws-cloudfront-origin-access-identity-module"><span class="std std-ref">cloudfront_origin_access_identity module</span></a> – Create, update and delete origin access identities for a CloudFront distribution</p></li>
 <li><p><a class="reference internal" href="cloudfront_response_headers_policy_module.html#ansible-collections-community-aws-cloudfront-response-headers-policy-module"><span class="std std-ref">cloudfront_response_headers_policy module</span></a> – Create, update and delete response headers policies to be used in a Cloudfront distribution</p></li>
diff --git a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/index_module.html b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/index_module.html
index 4c73fae..62aec14 100644
--- a/home/runner/work/community.aws/community.aws/docsbuild/base/collections/index_module.html
+++ b/home/runner/work/community.aws/community.aws/docsbuild/head/collections/index_module.html
@@ -142,6 +142,7 @@
 <li><p><a class="reference internal" href="community/aws/cloudformation_stack_set_module.html#ansible-collections-community-aws-cloudformation-stack-set-module"><span class="std std-ref">community.aws.cloudformation_stack_set</span></a> – Manage groups of CloudFormation stacks</p></li>
 <li><p><a class="reference internal" href="community/aws/cloudfront_distribution_module.html#ansible-collections-community-aws-cloudfront-distribution-module"><span class="std std-ref">community.aws.cloudfront_distribution</span></a> – Create, update and delete AWS CloudFront distributions</p></li>
 <li><p><a class="reference internal" href="community/aws/cloudfront_distribution_info_module.html#ansible-collections-community-aws-cloudfront-distribution-info-module"><span class="std std-ref">community.aws.cloudfront_distribution_info</span></a> – Obtain facts about an AWS CloudFront distribution</p></li>
+<li><p><a class="reference internal" href="community/aws/cloudfront_function_module.html#ansible-collections-community-aws-cloudfront-function-module"><span class="std std-ref">community.aws.cloudfront_function</span></a> – Manage AWS CloudFront Functions</p></li>
 <li><p><a class="reference internal" href="community/aws/cloudfront_invalidation_module.html#ansible-collections-community-aws-cloudfront-invalidation-module"><span class="std std-ref">community.aws.cloudfront_invalidation</span></a> – create invalidations for AWS CloudFront distributions</p></li>
 <li><p><a class="reference internal" href="community/aws/cloudfront_origin_access_identity_module.html#ansible-collections-community-aws-cloudfront-origin-access-identity-module"><span class="std std-ref">community.aws.cloudfront_origin_access_identity</span></a> – Create, update and delete origin access identities for a CloudFront distribution</p></li>
 <li><p><a class="reference internal" href="community/aws/cloudfront_response_headers_policy_module.html#ansible-collections-community-aws-cloudfront-response-headers-policy-module"><span class="std std-ref">community.aws.cloudfront_response_headers_policy</span></a> – Create, update and delete response headers policies to be used in a Cloudfront distribution</p></li>

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/1fb0b1f2ba70450387cd6b093acb3000

✔️ ansible-galaxy-importer SUCCESS in 4m 00s (non-voting)
✔️ build-ansible-collection SUCCESS in 11m 14s
✔️ ansible-test-splitter SUCCESS in 4m 21s
integration-community.aws-1 FAILURE in 3m 00s
Skipped 21 jobs

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/7d83d2f674a84295bc6f9b75611f88b3

ansible-galaxy-importer FAILURE in 3m 56s (non-voting)
✔️ build-ansible-collection SUCCESS in 11m 26s
✔️ ansible-test-splitter SUCCESS in 4m 26s
integration-community.aws-1 FAILURE in 3m 09s
Skipped 21 jobs

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/3c9131e9995749d1a41f08e1fa6c35fa

ansible-galaxy-importer FAILURE in 3m 45s (non-voting)
✔️ build-ansible-collection SUCCESS in 10m 54s
✔️ ansible-test-splitter SUCCESS in 4m 17s
integration-community.aws-1 FAILURE in 3m 07s
Skipped 21 jobs

@alinabuzachis
Copy link
Contributor

@boutetnico Thank you for working on this new module. The missing permissions need to be added here https://github.com/mattclay/aws-terminator.

@boutetnico
Copy link
Contributor Author

Thanks @alinabuzachis, I've sent a PR mattclay/aws-terminator#323.

@boutetnico boutetnico marked this pull request as draft October 16, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants