I am using Github Actions to test my Lambda function before deployment. I am new to Github Action and running a practice project. Everyother jobs in the workflow works fine but the test job keeps giving this role error even though there is a role attached to it. Here is my code:
test:
runs-on: ubuntu-latest
needs: upload
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Create test function
run: |
aws lambda create-function
--function-name test-function
--runtime python3.8
--code S3Bucket=my-github-action-89675,S3Key=${{ github.sha }}.zip
--handler lambda_function.lambda_handler
--role arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/lamda-github-action-role
- name: Wait 30 seconds
run: sleep 30
- name: Destroy test function
if: ${{ always() }}
run: aws lambda delete-function --function-name test-function
This the error I get:
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
aws: error: the following arguments are required: --role
Error: Process completed with exit code 252.
Any idea on what to do would be appricated!
I expect the test job to excute but it keeps giving error
2
Answers
I was finally able to figure it out. White spaces were the issue. I did it with one line and it solved. I then put the code back in its previous state and tried again and it also worked.
Does it behave the same if you quote the parameters? Where I’ve used expansions – be it from shell variables or input/secrets, I usually quote them (shellcheck expects it). An unexpected newline in any of them would split the command.