Created
July 14, 2020 18:24
-
-
Save dtelaroli/ffbebd858f5089bfb7532ff3d96fb7ea to your computer and use it in GitHub Desktop.
Creates an amplify subdomain with aws javascript sdk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Effect": "Allow", | |
"Action": [ | |
"amplify:GetDomainAssociation", | |
"amplify:updateDomainAssociation" | |
], | |
"Resource": { | |
"Fn::Sub": "arn:aws:amplify:${AWS::Region}:${AWS::AccountId}:apps/${yourAmplifyFrontendAppIdParameter}/domains/${yourAmplifyFrontendDomainParameter}" | |
} | |
} |
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.
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
Good solution for those that won't quickly step over the limit of 50 subdomains.