-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(lambda-python): add support for custom build image #15324
Closed
setu4993
wants to merge
3
commits into
aws:master
from
setu4993:feat/lambda-python-support-build-image
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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": "AssetParameters8fc4fd4f1abe3a706b6b352735cbfd7feb66aca750b63d920c6f018e9d665b9dS3Bucket0D7ED7BA" | ||
}, | ||
"S3Key": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
{ | ||
"Fn::Select": [ | ||
0, | ||
{ | ||
"Fn::Split": [ | ||
"||", | ||
{ | ||
"Ref": "AssetParameters8fc4fd4f1abe3a706b6b352735cbfd7feb66aca750b63d920c6f018e9d665b9dS3VersionKey5CD58274" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"Fn::Select": [ | ||
1, | ||
{ | ||
"Fn::Split": [ | ||
"||", | ||
{ | ||
"Ref": "AssetParameters8fc4fd4f1abe3a706b6b352735cbfd7feb66aca750b63d920c6f018e9d665b9dS3VersionKey5CD58274" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
] | ||
} | ||
}, | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"myhandlerServiceRole77891068", | ||
"Arn" | ||
] | ||
}, | ||
"Handler": "index.handler", | ||
"Runtime": "python3.8" | ||
}, | ||
"DependsOn": [ | ||
"myhandlerServiceRole77891068" | ||
] | ||
} | ||
}, | ||
"Parameters": { | ||
"AssetParameters8fc4fd4f1abe3a706b6b352735cbfd7feb66aca750b63d920c6f018e9d665b9dS3Bucket0D7ED7BA": { | ||
"Type": "String", | ||
"Description": "S3 bucket for asset \"8fc4fd4f1abe3a706b6b352735cbfd7feb66aca750b63d920c6f018e9d665b9d\"" | ||
}, | ||
"AssetParameters8fc4fd4f1abe3a706b6b352735cbfd7feb66aca750b63d920c6f018e9d665b9dS3VersionKey5CD58274": { | ||
"Type": "String", | ||
"Description": "S3 key for asset version \"8fc4fd4f1abe3a706b6b352735cbfd7feb66aca750b63d920c6f018e9d665b9d\"" | ||
}, | ||
"AssetParameters8fc4fd4f1abe3a706b6b352735cbfd7feb66aca750b63d920c6f018e9d665b9dArtifactHash3FD1FF77": { | ||
"Type": "String", | ||
"Description": "Artifact hash for asset \"8fc4fd4f1abe3a706b6b352735cbfd7feb66aca750b63d920c6f018e9d665b9d\"" | ||
} | ||
}, | ||
"Outputs": { | ||
"FunctionArn": { | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"myhandlerD202FA8E", | ||
"Arn" | ||
] | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
import * as path from 'path'; | ||
import { Runtime } from '@aws-cdk/aws-lambda'; | ||
import { App, CfnOutput, 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 fn = new lambda.PythonFunction(this, 'my_handler', { | ||
entry: path.join(__dirname, 'lambda-handler-custom-build-docker-image'), | ||
runtime: Runtime.PYTHON_3_8, | ||
dockerBuildImageOptions: { file: 'Dockerfile.build' }, | ||
}); | ||
|
||
new CfnOutput(this, 'FunctionArn', { | ||
value: fn.functionArn, | ||
}); | ||
} | ||
} | ||
|
||
const app = new App(); | ||
new TestStack(app, 'cdk-integ-lambda-python'); | ||
app.synth(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@setu4993 I think that I would prefer to adopt the same approach that is used by both
NodejsFunction
andGoFunction
and just allow the user to supply their ownDockerImage
. i.e.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, @corymhall! I should have some space to work on this and update it over the weekend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@corymhall : Thinking through this a bit more, I'm open to switching to that structure, but I think it'd require quite a bit of refactoring of the current dependency installation system since this isn't inheriting from
cdk.BundlingOptions
right now... I'm open to doing that (possibly in a separate PR first) and then inheriting those changes to support bundling here. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@setu4993 If you are willing to work on that refactoring then I think it is a good idea! Before making this library stable we would want to bring it in line with the other two anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@corymhall : What do you think about #18082? The allure of getting
lambda-Python
to stable (finally!) was enough motivation :).