Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧪 Add SAM invoke lambda-function test #1332

Merged
merged 9 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions .github/workflows/build-test-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Configure aws credentials and assume github-actions role
- name: Configure AWS credentials and assume github-actions role
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
role-session-name: githubactionsrolesession
aws-region: ${{ env.AWS_REGION }}
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version: ">=1.18"
go-version: "1.23"
cache-dependency-path: "**/go.sum"
- uses: aws-actions/setup-sam@2360ef6d90015369947b45b496193ab9976a9b04 # v2
- name: SAM Validate
Expand All @@ -53,6 +53,25 @@ jobs:
# Build inside Docker containers
- name: SAM Build
run: sam build --use-container --region ${{ env.AWS_REGION }}
- name: SAM Local Invoke
run: |
aws sts assume-role --role-arn $LAMBDA_ROLE_ARN --role-session-name githubactionsgotestrolesession > creds
export AWS_ACCESS_KEY_ID=$(cat creds | jq -r '.Credentials.AccessKeyId')
export AWS_SECRET_ACCESS_KEY=$(cat creds | jq -r '.Credentials.SecretAccessKey')
export AWS_SESSION_TOKEN=$(cat creds | jq -r '.Credentials.SessionToken')

# Capture SAM output in a variable
SAM_OUTPUT=$(sam local invoke InstanceSchedulerFunction --event event.json 2>&1)
echo "$SAM_OUTPUT"

# Check for errors in the output
if echo "$SAM_OUTPUT" | grep -i "error"; then
echo "Error detected in SAM invoke output."
exit 1
fi

unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN

- name: Download Go Modules
working-directory: instance-scheduler
run: go mod download
Expand All @@ -66,7 +85,7 @@ jobs:
aws sts get-caller-identity
go test -v
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
- name: Configure aws credentials and assume github-actions role
- name: Configure AWS credentials and assume github-actions role
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
Expand Down