-
-
Save filipemacedo/6c2fe68efcc9958e9948b738fbc1e427 to your computer and use it in GitHub Desktop.
Creates an amplify subdomain with aws javascript sdk
This file contains 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 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}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment