-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add bundling, integ test for custom Docker image
- Loading branch information
Showing
6 changed files
with
188 additions
and
0 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
113 changes: 113 additions & 0 deletions
113
packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json
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,113 @@ | ||
{ | ||
"Resources": { | ||
"myhandlerServiceRole77891068": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"myhandlerD202FA8E": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"S3Bucket": { | ||
"Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE" | ||
}, | ||
"S3Key": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
{ | ||
"Fn::Select": [ | ||
0, | ||
{ | ||
"Fn::Split": [ | ||
"||", | ||
{ | ||
"Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"Fn::Select": [ | ||
1, | ||
{ | ||
"Fn::Split": [ | ||
"||", | ||
{ | ||
"Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
] | ||
} | ||
}, | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"myhandlerServiceRole77891068", | ||
"Arn" | ||
] | ||
}, | ||
"Handler": "index.handler", | ||
"Runtime": "python3.7" | ||
}, | ||
"DependsOn": [ | ||
"myhandlerServiceRole77891068" | ||
] | ||
} | ||
}, | ||
"Parameters": { | ||
"AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE": { | ||
"Type": "String", | ||
"Description": "S3 bucket for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" | ||
}, | ||
"AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1": { | ||
"Type": "String", | ||
"Description": "S3 key for asset version \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" | ||
}, | ||
"AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374ArtifactHashDECBC32A": { | ||
"Type": "String", | ||
"Description": "Artifact hash for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" | ||
} | ||
}, | ||
"Outputs": { | ||
"FunctionArn": { | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"myhandlerD202FA8E", | ||
"Arn" | ||
] | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.ts
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,29 @@ | ||
import * as path from 'path'; | ||
import { App, CfnOutput, DockerImage, Stack, StackProps } from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import * as lambda from '../lib'; | ||
|
||
/* | ||
* Stack verification steps: | ||
* * aws lambda invoke --function-name <deployed fn name> --invocation-type Event --payload '"OK"' response.json | ||
*/ | ||
|
||
class TestStack extends Stack { | ||
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
const entry = path.join(__dirname, 'lambda-handler-custom-build'); | ||
const fn = new lambda.PythonFunction(this, 'my_handler', { | ||
entry: entry, | ||
bundling: { image: DockerImage.fromBuild(path.join(entry)) }, | ||
}); | ||
|
||
new CfnOutput(this, 'FunctionArn', { | ||
value: fn.functionArn, | ||
}); | ||
} | ||
} | ||
|
||
const app = new App(); | ||
new TestStack(app, 'cdk-integ-lambda-custom-build'); | ||
app.synth(); |
3 changes: 3 additions & 0 deletions
3
packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/Dockerfile
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,3 @@ | ||
FROM public.ecr.aws/sam/build-python3.7 | ||
|
||
CMD [ "python" ] |
11 changes: 11 additions & 0 deletions
11
packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/index.py
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,11 @@ | ||
import requests | ||
from PIL import Image | ||
|
||
def handler(event, context): | ||
response = requests.get('https://a0.awsstatic.com/main/images/logos/aws_smile-header-desktop-en-white_59x35.png', stream=True) | ||
img = Image.open(response.raw) | ||
|
||
print(response.status_code) | ||
print(img.size) | ||
|
||
return response.status_code |
9 changes: 9 additions & 0 deletions
9
packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/requirements.txt
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,9 @@ | ||
# Lock versions of pip packages | ||
certifi==2020.6.20 | ||
chardet==3.0.4 | ||
idna==2.10 | ||
urllib3==1.26.7 | ||
# Requests used by this lambda | ||
requests==2.26.0 | ||
# Pillow 6.x so that python 2.7 and 3.x can both use this fixture | ||
Pillow==8.4.0 |