Skip to content

Instantly share code, notes, and snippets.

@dtelaroli
Created July 14, 2020 18:24
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dtelaroli/ffbebd858f5089bfb7532ff3d96fb7ea to your computer and use it in GitHub Desktop.
Save dtelaroli/ffbebd858f5089bfb7532ff3d96fb7ea to your computer and use it in GitHub Desktop.
Creates an amplify subdomain with aws javascript sdk
const { to } = require("await-to-js");
const { Amplify } = require("aws-sdk");
const amplify = new Amplify();
const config = {
AMPLIFY_FRONTEND_APP_ID: "your_app_id",
AMPLIFY_FRONTEND_DOMAIN: "your_domain.com",
AMPLIFY_FRONTEND_BRANCH: "your_branch_env"
};
const createSubdomain = async (prefix) => {
const paramsGet = {
appId: config.AMPLIFY_FRONTEND_APP_ID, /* required */
domainName: config.AMPLIFY_FRONTEND_DOMAIN /* required */
};
const [errorGet, domainAssociation] = await to(amplify.getDomainAssociation(paramsGet).promise());
if (errorGet) return [errorGet.message];
const params = {
appId: config.AMPLIFY_FRONTEND_APP_ID, /* required */
domainName: config.AMPLIFY_FRONTEND_DOMAIN, /* required */
subDomainSettings: [ /* required */
...domainAssociation.domainAssociation.subDomains.map(subdmain => ({
...subdmain.subDomainSetting
})),
{
branchName: config.AMPLIFY_FRONTEND_BRANCH, /* required */
prefix /* required */
}
]
};
return to(amplify.updateDomainAssociation(params).promise());
}
{
"Effect": "Allow",
"Action": [
"amplify:GetDomainAssociation",
"amplify:updateDomainAssociation"
],
"Resource": {
"Fn::Sub": "arn:aws:amplify:${AWS::Region}:${AWS::AccountId}:apps/${yourAmplifyFrontendAppIdParameter}/domains/${yourAmplifyFrontendDomainParameter}"
}
}
@cjimenezber
Copy link

Good solution for those that won't quickly step over the limit of 50 subdomains.

@dtelaroli
Copy link
Author

You can ask for increase the limit:

image

@Kaustubh26
Copy link

Great solution but did the limit increase request actually work? I had raised a similar case some time back and they came back saying it's not possible to go beyond 50.

@dtelaroli
Copy link
Author

I just have ask for increase limit, but now I saw that the limit is for domains, not about subdomains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment