Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Updated runtime to Python 3.8, and fixed binary release URLs to again…
Browse files Browse the repository at this point in the history
… enable the two quick deploy options.
  • Loading branch information
davfaulk committed May 24, 2021
1 parent 67a6122 commit 5a976b7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM amazonlinux:1
RUN yum install -y python36-pip zip && yum clean all
FROM amazonlinux:2
RUN yum install -y amazon-linux-extras && amazon-linux-extras enable python3.8
RUN yum install -y python3.8 zip && yum clean all
COPY src /build
RUN pip-3.6 install -r /build/requirements.txt -t /build/python/
RUN pip3.8 install -r /build/requirements.txt -t /build/python/
WORKDIR /build
CMD sh build_package.sh
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ And then run `sh deploy.sh`

## Deploy Manually (Lambda Console)

1. Create a lambda function (python 3.6 runtime), and update the code to the contents of src/lambda.py
1. Create a lambda function (python 3.8 runtime), and update the code to the contents of src/lambda.py
2. Create a lambda IAM execution role with ce:, ses:, s3:, organizations:ListAccounts
3. Configure the dependency layer: arn:aws:lambda:us-east-1:749981256976:layer:aws-cost-explorer-report:1
3. Configure the dependency layer: arn:aws:lambda:us-east-1:749981256976:layer:CostExplorerReportLayer:1
4. Update ENV Variables in Lambda console
* Details in table above.
5. Create a trigger (CloudWatch Event)
Expand Down
8 changes: 7 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export AWS_DEFAULT_REGION=us-east-1
#Change the below, an s3 bucket to store lambda code for deploy, and output report
#Must be in same region as lambda (ie AWS_DEFAULT_REGION)
export BUCKET=changeme
export BUCKET=CHANGEME_THIS_IS_NOT_A_VALID_S3_BUCKET
#Comma Seperated list of emails to send to
export [email protected],[email protected]
export [email protected]
Expand All @@ -15,6 +15,12 @@ export CURRENT_MONTH=false
#Day of Month, leave as 6 unless you want to capture refunds and final support values, then change to 12
export DAY_MONTH=6

if [ ! -f bin/lambda.zip ]; then
echo "lambda.zip not found! Downloading one we prepared earlier"
curl -L https://aws-cost-explorer-report-release.s3.amazonaws.com/lambda.zip --create-dirs -o bin/lambda.zip
curl -L https://aws-cost-explorer-report-release.s3.amazonaws.com/layer.zip --create-dirs -o bin/layer.zip
fi

cd src
zip -ur ../bin/lambda.zip lambda.py
cd ..
Expand Down
15 changes: 12 additions & 3 deletions easy_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ Parameters:
Description: DayOfMonth for Schedule, default 6 - use 12 if you want to report
refunds and finalised Enterprise Support.
Resources:
CostExplorerReportLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: s3://aws-cost-explorer-report-release/layer.zip
CompatibleRuntimes:
- python3.8
Metadata:
BuildMethod: python3.8

CostExplorerReport:
Type: AWS::Serverless::Function
Properties:
Expand All @@ -39,10 +48,10 @@ Resources:
MemorySize: 256
Timeout: 60
Handler: lambda.main_handler
Runtime: python3.6
CodeUri: s3://aws-cost-explorer-report-bin/lambda.zip
Runtime: python3.8
CodeUri: s3://aws-cost-explorer-report-release/lambda.zip
Layers:
- arn:aws:lambda:us-east-1:749981256976:layer:aws-cost-explorer-report:1
- Ref: CostExplorerReportLayer
Role:
Fn::GetAtt:
- CostExplorerReportLambdaIAMRole
Expand Down
11 changes: 7 additions & 4 deletions src/lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,13 @@ def main_handler(event=None, context=None):
costexplorer.addReport(Name="{}".format(tabname)[:31], GroupBy=[{"Type": "TAG","Key": tagkey}],Style='Total')
costexplorer.addReport(Name="Change-{}".format(tabname)[:31], GroupBy=[{"Type": "TAG","Key": tagkey}],Style='Change')
#RI Reports
costexplorer.addRiReport(Name="RICoverage")
costexplorer.addRiReport(Name="RIUtilization")
costexplorer.addRiReport(Name="RIUtilizationSavings", Savings=True)
costexplorer.addRiReport(Name="RIRecommendation") #Service supported value(s): Amazon Elastic Compute Cloud - Compute, Amazon Relational Database Service
try:
costexplorer.addRiReport(Name="RICoverage")
costexplorer.addRiReport(Name="RIUtilization")
costexplorer.addRiReport(Name="RIUtilizationSavings", Savings=True)
costexplorer.addRiReport(Name="RIRecommendation") #Service supported value(s): Amazon Elastic Compute Cloud - Compute, Amazon Relational Database Service
except Exception:
pass #Don't fail if account doesnt have any RI use
costexplorer.generateExcel()
return "Report Generated"

Expand Down
16 changes: 11 additions & 5 deletions src/sam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ Parameters:
Description: "DayOfMonth for Schedule, default 6 - use 12 if you want to report refunds and finalised Enterprise Support."

Resources:
CostExplorerReportLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: ../bin/layer.zip
CompatibleRuntimes:
- python3.8
Metadata:
BuildMethod: python3.8

CostExplorerReport:
Type: 'AWS::Serverless::Function'
Properties:
Expand All @@ -38,14 +47,11 @@ Resources:
MemorySize: 256
Timeout: 60
Handler: lambda.main_handler
Runtime: python3.6
Runtime: python3.8
CodeUri: ../bin/lambda.zip
Layers:
- arn:aws:lambda:us-east-1:749981256976:layer:aws-cost-explorer-report:1
- !Ref CostExplorerReportLayer
Role: !GetAtt CostExplorerReportLambdaIAMRole.Arn
Environment:
Variables:
TABLE_NAME: !Ref Table
Environment:
Variables:
S3_BUCKET: !Ref S3Bucket
Expand Down

0 comments on commit 5a976b7

Please sign in to comment.