-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix package data inclusion * Fix getting outputs of a erroneously deployed stack * Remove ResponseMetadata from configuration * Remove ResponseMetadata from API response * Update data-capture destination * Fix contents look up * Fix typo * Remove stack outputs cashing * Add CopyZips function * Add template to package distribution * Remove template URL * Convert traffic_shadowing to package * Update source bucket * Rename function parameters * Update IAM policy * Update distribution bucket
- Loading branch information
1 parent
7540f56
commit 6e4068e
Showing
21 changed files
with
432 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,5 +247,4 @@ $RECYCLE.BIN/ | |
.idea/ | ||
.envrc | ||
events/ | ||
template_version.txt | ||
test-report.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from hydro_integrations.aws.sagemaker.traffic_shadowing import TrafficShadowing | ||
from hydro_integrations.aws.sagemaker.traffic_shadowing.traffic_shadowing import TrafficShadowing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# pylint: disable=missing-class-docstring | ||
from hydro_integrations.aws.exceptions import NotFound | ||
|
||
class DataCaptureConfigException(Exception): | ||
|
||
class FunctionNotFound(NotFound): | ||
pass | ||
|
||
|
||
class FunctionNotFound(Exception): | ||
class DataCaptureConfigException(Exception): | ||
pass |
Empty file.
151 changes: 151 additions & 0 deletions
151
hydro_integrations/aws/sagemaker/traffic_shadowing/template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Description: > | ||
CloudFormation template to deploy resources for shadowing traffic from SageMaker | ||
Model Endpoint to Hydrosphere instance. | ||
Parameters: | ||
S3DataCaptureBucketName: | ||
Type: String | ||
S3DataCapturePrefix: | ||
Type: String | ||
S3DataTrainingBucketName: | ||
Type: String | ||
S3DataTrainingPrefix: | ||
Type: String | ||
HydrosphereEndpoint: | ||
Type: String | ||
Resources: | ||
LambdaInvokePermission: | ||
Type: 'AWS::Lambda::Permission' | ||
Properties: | ||
FunctionName: !GetAtt TrafficShadowingFunction.Arn | ||
Action: 'lambda:InvokeFunction' | ||
Principal: s3.amazonaws.com | ||
SourceAccount: !Ref 'AWS::AccountId' | ||
SourceArn: !Sub 'arn:aws:s3:::${S3DataCaptureBucketName}' | ||
LambdaExecutionRole: | ||
Type: AWS::IAM::Role | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: Allow | ||
Principal: | ||
Service: | ||
- lambda.amazonaws.com | ||
Action: | ||
- sts:AssumeRole | ||
Path: '/' | ||
Policies: | ||
- PolicyName: traffic-shadowing-policy | ||
PolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: Allow | ||
Action: | ||
- s3:* | ||
Resource: '*' | ||
- Effect: Allow | ||
Action: | ||
- logs:* | ||
Resource: arn:aws:logs:*:*:* | ||
LambdaZipsBucket: | ||
Type: AWS::S3::Bucket | ||
CopyZips: | ||
Type: Custom::CopyZips | ||
Properties: | ||
ServiceToken: !GetAtt CopyZipsFunction.Arn | ||
DestRegion: !Ref AWS::Region | ||
DestBucket: !Ref LambdaZipsBucket | ||
SourceBucket: hydrosphere-integrations-eu-west-3 | ||
Prefix: "" | ||
Objects: | ||
- lambda/traffic_shadowing/1a46812f177b62fc77b02818f04c0ff4 | ||
CopyZipsFunction: | ||
Type: AWS::Lambda::Function | ||
Properties: | ||
Description: Copies objects from a source S3 bucket to a destination bucket | ||
Handler: index.handler | ||
Runtime: python3.7 | ||
Role: !GetAtt LambdaExecutionRole.Arn | ||
Timeout: 240 | ||
Code: | ||
ZipFile: | | ||
import json | ||
import logging | ||
import threading | ||
import boto3 | ||
import cfnresponse | ||
def copy_objects(source_bucket, dest_bucket, prefix, objects): | ||
s3 = boto3.client('s3') | ||
for o in objects: | ||
key = prefix + o | ||
copy_source = { | ||
'Bucket': source_bucket, | ||
'Key': key | ||
} | ||
s3.copy_object( | ||
CopySource=copy_source, | ||
Bucket=dest_bucket, | ||
Key=key, | ||
RequestPayer='requester', | ||
) | ||
def delete_objects(bucket, prefix, objects): | ||
s3 = boto3.client('s3') | ||
objects = {'Objects': [{'Key': prefix + o} for o in objects]} | ||
s3.delete_objects(Bucket=bucket, Delete=objects) | ||
def timeout(event, context): | ||
logging.error('Execution is about to time out, sending failure response to CloudFormation') | ||
cfnresponse.send(event, context, cfnresponse.FAILED, {}, None) | ||
def handler(event, context): | ||
# make sure we send a failure to CloudFormation if the function is going to timeout | ||
timer = threading.Timer((context.get_remaining_time_in_millis() / 1000.00) - 0.5, timeout, args=[event, context]) | ||
timer.start() | ||
print('Received event: %s' % json.dumps(event)) | ||
status = cfnresponse.SUCCESS | ||
try: | ||
source_bucket = event['ResourceProperties']['SourceBucket'] | ||
dest_bucket = event['ResourceProperties']['DestBucket'] | ||
prefix = event['ResourceProperties']['Prefix'] | ||
objects = event['ResourceProperties']['Objects'] | ||
if event['RequestType'] == 'Delete': | ||
delete_objects(dest_bucket, prefix, objects) | ||
else: | ||
copy_objects(source_bucket, dest_bucket, prefix, objects) | ||
except Exception as e: | ||
logging.error('Exception: %s' % e, exc_info=True) | ||
status = cfnresponse.FAILED | ||
finally: | ||
timer.cancel() | ||
cfnresponse.send(event, context, status, {}, None) | ||
TrafficShadowingFunction: | ||
DependsOn: CopyZips | ||
Type: AWS::Lambda::Function | ||
Properties: | ||
Description: | | ||
Stateless function, triggered by s3:ObjectCreated:* events. | ||
Registers external models, uploads training data, submits | ||
production data for analysis. | ||
Code: | ||
S3Bucket: !Ref LambdaZipsBucket | ||
S3Key: lambda/traffic_shadowing/1a46812f177b62fc77b02818f04c0ff4 | ||
Timeout: 240 | ||
MemorySize: 256 | ||
Runtime: python3.7 | ||
Handler: src.handler.lambda_handler | ||
Role: !GetAtt LambdaExecutionRole.Arn | ||
Environment: | ||
Variables: | ||
S3_DATA_CAPTURE_BUCKET: !Ref S3DataCaptureBucketName | ||
S3_DATA_CAPTURE_PREFIX: !Ref S3DataCapturePrefix | ||
S3_DATA_TRAINING_BUCKET: !Ref S3DataTrainingBucketName | ||
S3_DATA_TRAINING_PREFIX: !Ref S3DataTrainingPrefix | ||
HYDROSPHERE_ENDPOINT: !Ref HydrosphereEndpoint | ||
ReservedConcurrentExecutions: 3 | ||
TrafficShadowingVersion: | ||
Type: AWS::Lambda::Version | ||
Properties: | ||
FunctionName: !Ref TrafficShadowingFunction | ||
Outputs: | ||
TrafficShadowingFunctionArn: | ||
Value: !GetAtt TrafficShadowingFunction.Arn |
Oops, something went wrong.