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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南