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

Modify serverless.yml and documentation to fit evolution of serverles… #19

Merged
merged 2 commits into from
Mar 25, 2022

Conversation

ohe
Copy link
Contributor

@ohe ohe commented Feb 22, 2022

…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.

@dudeitssm
Copy link
Contributor

dudeitssm commented Feb 22, 2022

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:
ohe/aws-billing-to-slack@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 👍

* Update serverless.yml

* Require python v3.9

Co-authored-by: dudeitssm <36095297+dudeitssm@users.noreply.github.com>
@ohe
Copy link
Contributor Author

ohe commented Feb 23, 2022

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 !

@iandees
Copy link
Owner

iandees commented Mar 25, 2022

Thanks for your update here!

@iandees iandees merged commit c856ae0 into iandees:master Mar 25, 2022
@ohe ohe deleted the support_serverless_3.x branch April 7, 2022 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants