Closed ohe closed 2 years ago
Hi Olivier.
First, thank you kindly for the PR. It helped me out a lot!
Unfortunately, your changes didn't completely fix it for me. However, to get it working, I just needed two minor tweaks: https://github.com/ohe/aws-billing-to-slack/compare/support_serverless_3.x...dudeitssm:master
In short, I had to change the Pipfile
to make python use 3.9. Without it, I got the following error:
Error: `pipenv lock --requirements --keep-outdated` Exited with code 1
at ChildProcess.<anonymous> (/home/fedora/awscost/app-aws-cost/node_modules/child-process-ext/spawn.js:38:8)
at ChildProcess.emit (events.js:376:20)
at ChildProcess.emit (domain.js:470:12)
at maybeClose (internal/child_process.js:1055:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
Additionally, I had to add param:aws_profile
in order to be able to supply the AWS profile (as I have too many accounts to manage, and by default, it uses the default
profile).
With these changes, I was able to deploy the app successfully. This was the exact command I ran:
serverless deploy \
--stage="prod" \
--param=aws_profile=COMPANY_NAME \
--param=aws_region="us-east-1" \
--param=aws_account=COMPANY_ALIAS \
--param=slack_url="https://hooks.slack.com/12345"
To invoke the function manually:
serverless invoke \
--stage="prod" \
--function report_cost \
--param=aws_profile=COMPANY_NAME \
--param=aws_region="us-east-1" \
--param=aws_account=COMPANY_ALIAS \
--param=slack_url="https://hooks.slack.com/12345"
Unfortunately, I can't test it yet, as I just enabled Costs Explorer; have to wait until tomorrow until I see it working. Here's what the Cloudwatch logs show for the function if you did not have Costs Explorer enabled:
[ERROR] ClientError: An error occurred (AccessDeniedException) when calling the GetCostAndUsage operation: User not enabled for cost explorer access
Traceback (most recent call last):
File "/var/task/handler.py", line 101, in report_cost
result = client.get_cost_and_usage(**query)
File "/var/task/botocore/client.py", line 391, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/task/botocore/client.py", line 719, in _make_api_call
raise error_class(parsed_response, operation_name)
Thanks again, and feel free to merge my changes :+1:
Hi @dudeitssm & thanks for your comment. I have integrated them so this PR contains now your changes. I'm really surprised that pipfile/pipenv did not complain on my environment as your change truly makes sense.
Thanks !
Thanks for your update here!
…s framework.
Serverless, in its 3.x version does not support "custom" cli options (see: https://www.serverless.com/framework/docs/deprecations/#UNSUPPORTED_CLI_OPTIONS). This PR is modifying the serverless.yml file and Documentation to fit the latest serverless framework version.