Expand my Community achievements bar.

SOLVED

How to clear Fastly cache in AEM cloud ?

Avatar

Level 9

I want to clear cache in Fastly in aem as a cloud service. Is there any curl command to clear the cache ?  I tried with below command

 

curl -X PURGE https://publish-pxxx-exxx.adobeaemcloud.com/content/my-project/test.html

 

I get "Unauthorized" error message. How do we get "x-aem-purge-key"? Is there any other option available ?

1 Accepted Solution

Avatar

Correct answer by
Level 8

Hi @Mario248,

the CDN config folder should be in the root folder of your project/codebase, not under Dispatcher in any way. Also, make sure to push the changes to Adobe Git. That should be it.

The dot in the folder name is not a problem, I just like it to be on top.

 

Good luck,

Daniel

View solution in original post

8 Replies

Avatar

Community Advisor

@Mario248 

You can get the x-aem-purge-key from Adobe team. They can share it for your cloud service environments

However , you can configure Purge API token yourself too, by declaring it in cdn.yaml file as below

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/con...

Once you have the Purge Key, use the below Curl to purge cache
curl
-X PURGE "https://publish-p1234-e5467.adobeaemcloud.com/resource-path" \
-H 'X-AEM-Purge-Key: <my_purge_key>' \
-H 'X-AEM-Purge: soft'

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/con...

Avatar

Community Advisor

@Mario248 I hope @AMANATH_ULLAH answer helps you. On top of this I want to share the official doc link with more Cache Purge options on AEM Cloud 

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/con...

 

Hope it help.

Avatar

Level 9

I have followed the doc and created a cdn.yaml file inside ../dispatcher/src/conf.d/cdn.yaml.

 

kind: "CDN"
version: "1"
metadata:
  envTypes: ["dev", "stage", "prod"]
data:
  authentication: # The main authentication configuration
    authenticators: # The list of authenticators
      - name: purge-auth # The name of the authenticator
        type: purge  # The type of the authenticator, must be purge
        purgeKey1: ${{CDN_PURGEKEY_081324}} # The first purge key, must be referenced by the Cloud Manager secret-type environment variable name ${{CDN_EDGEKEY_073124}}
        purgeKey2: ${{CDN_PURGEKEY_111324}} # The second purge key, must be referenced by the Cloud Manager secret-type environment variable name ${{CDN_EDGEKEY_111324}}. It is used for the rotation of secrets without any interruptions.
    rules: # The list of authentication rules
      - name: purge-auth-rule # The name of the rule
        when: { reqProperty: tier, equals: "publish" } # The condition when the rule should be applied
        action: # The action to be taken when the rule is applied
          type: authenticate # The type of the action, must be authenticate
          authenticator: purge-auth # The name of the authenticator to be used, must match the name from the above authenticators list

 

 

And created a cloud manager variable as described

Mario248_0-1727183057257.png

 

But still I get "Unauthorized Purge" error. Any idea ? Did I place the cdn.yaml file in correct location ?

 

Avatar

Level 8

Hi @Mario248,

don't mix your CDN config and Apache/Dispatcher config. You should place the cnd.yaml file in a dedidated folder in the root of your project, for example .config/dev/cnd.yaml. Then you need to create a config pipeline poiting to that folder, to get your CDN configuration deployed.

 

Screenshot 2024-09-19 at 12.13.47 (1).png

 

Hope this helps,

Daniel

Avatar

Level 9

Thanks for your response Daniel. I have created a new config pipeline as you mentioned above and also moved a cdn.yaml file to "dispatcher/src/.config/dev/cdn.yaml"

 

Mario248_0-1727239190397.png

Mario248_0-1727239613669.png

 

 

 

I get this error while running the pipeline - 

[ERROR] Error while processing the download and upload to shareName. Cause: InvalidStatusCodeRuntimeException while executing the request
 
I tried without "." like config/dev/cdn.yaml and configured the same in pipeline as "/config/dev" but I get the same error. I also validated the yaml using

"yq eval ****/dev/cdn.yaml"

Am I missing anything ?

Avatar

Community Advisor

@Mario248 

cdn.yaml file should be placed in config folder which is on the root hierarchy. It should not be part of dispatcher folder.

Please see the sample structure in below link

https://github.com/adobe/aem-guides-wknd/tree/main/config

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/operations/confi...

 

 

Avatar

Correct answer by
Level 8

Hi @Mario248,

the CDN config folder should be in the root folder of your project/codebase, not under Dispatcher in any way. Also, make sure to push the changes to Adobe Git. That should be it.

The dot in the folder name is not a problem, I just like it to be on top.

 

Good luck,

Daniel

Avatar

Level 9

It works Daniel. Thank you for your input and response.