Search code examples
amazon-web-servicesaws-amplifyaws-amplify-cli

amplify init (headless) always pushes to aws


im trying to do an amplify init in jenkins job. so this needs to be done headless. taking inspiration from the code repo

i have prepared this code

# #!/bin/bash
set -e
IFS='|'
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"general\",\
\"useProfile\":false,\
\"accessKeyId\":\"${AWS_ACCESS_KEY_ID}\",\
\"secretAccessKey\":\"${AWS_SECRET_ACCESS_KEY}\",\
\"region\":\"${region}\"\
}"

AMPLIFY="{\"envName\":\"${AMPLIFY_ENV}\", \"defaultEditor\":\"code\"}"
PROVIDERS="{\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG}"

echo 'Initializing Amplify'
amplify init \
--amplify $AMPLIFY \
--providers $PROVIDERS \
--yes
echo 'Amplify Initialized'

the question is that doing an amplify init from console does not push the resources to cloud. but doing an amplify init (headless) way. even if an existing environment is used every change is pushed to the cloud.

What im trying to achieve it to create/generate the API.service.ts file so that my team does not have to include it in the repository.


Solution

  • the --yes was the issue.

    this works

    # #!/bin/bash
    set -e
    IFS='|'
    AWSCLOUDFORMATIONCONFIG="{\
    \"configLevel\":\"general\",\
    \"useProfile\":false,\
    \"accessKeyId\":\"${AWS_ACCESS_KEY_ID}\",\
    \"secretAccessKey\":\"${AWS_SECRET_ACCESS_KEY}\",\
    \"region\":\"${region}\"\
    }"
    
    AMPLIFY="{\"envName\":\"${AMPLIFY_ENV}\", \"defaultEditor\":\"code\"}"
    PROVIDERS="{\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG}"
    
    echo 'Initializing Amplify'
    amplify init \
    --amplify $AMPLIFY \
    --providers $PROVIDERS
    echo 'Amplify Initialized'