Using AWS Secrets Manager with n8n: Handling Hyphens and JSON
Introduction
When integrating AWS Secrets Manager with n8n, you may encounter limitations related to secret naming conventions and data formats. This guide provides a workaround for handling hyphens in secret names and accessing JSON objects.
Limitations
Hyphens in Secret Names: n8n officially supports only alphanumeric characters (a-z, A-Z, 0-9) and underscores in secret names. Hyphens are not supported.
Key-Value Pairs: n8n currently supports only plaintext values for secrets, not JSON objects or key-value pairs.
Workaround
To work around these limitations, use the following expression:
{{ JSON.parse($secrets.awsSecretsManager["n8n-platform-postgre"]).host }}
Explanation
Bracket Notation: Use bracket notation ["n8n-platform-postgre"] to reference a secret with unsupported characters like hyphens.
JSON.parse(): This function converts the key-value pair back to JSON, allowing you to access specific properties such as
.password.
Expected Behavior
When you set up the credential with this expression, n8n will display "undefined" in the credential configuration screen. This is expected and does not indicate a malfunction. The credential will function correctly in your workflows.
Conclusion
While this workaround is not part of the official documentation, it provides a practical solution for users who cannot modify their existing infrastructure to meet n8n's requirements. We recommend passing this feedback to the engineering and documentation teams for further improvements.