How do create an Amplify app via CloudFormation without using AWS Console?

0

At my employer, we use CloudFormation for managing our stacks. In the case of Amplify, I want to add an Amplify resource to my template.yml and have AWS provision it.

The docs say that I need an access token (I'm using GitHub) in order to do this. The docs also say that the only way to get that access token is to create an Amplify app via the AWS console. I don't want to do this and even if I did, I am not an admin for our GitHub repositories so I can't.

How can this be done without touching the AWS console?

Sam
已提问 7 个月前417 查看次数
1 回答
0

Hello Once you have the PAT, you should store it securely in AWS Secrets Manager.

Use AWS CLI to create a secret:

aws secretsmanager create-secret --name GitHubToken --description "GitHub Personal Access Token" --secret-string "YOUR_GITHUB_TOKEN"

Remember the ARN of the secret you just created, as it will be needed in the CloudFormation template.

Create CloudFormation Template Now you can create a CloudFormation template that provisions the Amplify app:

Resources:
  MyAmplifyApp:
    Type: "AWS::Amplify::App"
    Properties:
      Name: MyAppName
      Repository: https://github.com/yourusername/yourrepository.git
      AccessToken: !Sub
        - '{{resolve:secretsmanager:${SecretARN}:SecretString:token}}'
        - SecretARN: arn:aws:secretsmanager:region:account-id:secret:GitHubToken-abcdef
      OauthToken: !Sub
        - '{{resolve:secretsmanager:${SecretARN}:SecretString:token}}'
        - SecretARN: arn:aws:secretsmanager:region:account-id:secret:GitHubToken-abcdef

Deploy the CloudFormation Template Now you can deploy the CloudFormation template using the AWS CLI or any CI/CD pipeline you have in place:

aws cloudformation deploy --template-file template.yml --stack-name MyAmplifyStack

After the stack is successfully created, AWS will provision an Amplify app connected to your GitHub repository using the Personal Access Token stored in AWS Secrets Manager.

Regards, Andrii

profile picture
专家
已回答 7 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则