Location
- class aws_cdk.aws_s3.Location(*, bucket_name, object_key, object_version=None)
Bases:
object
An interface that represents the location of a specific object in an S3 Bucket.
- Parameters:
bucket_name (
str
) – The name of the S3 Bucket the object is in.object_key (
str
) – The path inside the Bucket where the object is located at.object_version (
Optional
[str
]) – The S3 object version.
- ExampleMetadata:
lit=aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts infused
Example:
lambda_stack = cdk.Stack(app, "LambdaStack") lambda_code = lambda_.Code.from_cfn_parameters() lambda_.Function(lambda_stack, "Lambda", code=lambda_code, handler="index.handler", runtime=lambda_.Runtime.NODEJS_LATEST ) # other resources that your Lambda needs, added to the lambdaStack... pipeline_stack = cdk.Stack(app, "PipelineStack") pipeline = codepipeline.Pipeline(pipeline_stack, "Pipeline", cross_account_keys=True ) # add the source code repository containing this code to your Pipeline, # and the source code of the Lambda Function, if they're separate cdk_source_output = codepipeline.Artifact() cdk_source_action = codepipeline_actions.CodeCommitSourceAction( repository=codecommit.Repository(pipeline_stack, "CdkCodeRepo", repository_name="CdkCodeRepo" ), action_name="CdkCode_Source", output=cdk_source_output ) lambda_source_output = codepipeline.Artifact() lambda_source_action = codepipeline_actions.CodeCommitSourceAction( repository=codecommit.Repository(pipeline_stack, "LambdaCodeRepo", repository_name="LambdaCodeRepo" ), action_name="LambdaCode_Source", output=lambda_source_output ) pipeline.add_stage( stage_name="Source", actions=[cdk_source_action, lambda_source_action] ) # synthesize the Lambda CDK template, using CodeBuild # the below values are just examples, assuming your CDK code is in TypeScript/JavaScript - # adjust the build environment and/or commands accordingly cdk_build_project = codebuild.Project(pipeline_stack, "CdkBuildProject", environment=codebuild.BuildEnvironment( build_image=codebuild.LinuxBuildImage.STANDARD_7_0 ), build_spec=codebuild.BuildSpec.from_object({ "version": "0.2", "phases": { "install": { "commands": "npm install" }, "build": { "commands": ["npm run build", "npm run cdk synth LambdaStack -- -o ." ] } }, "artifacts": { "files": "LambdaStack.template.yaml" } }) ) cdk_build_output = codepipeline.Artifact() cdk_build_action = codepipeline_actions.CodeBuildAction( action_name="CDK_Build", project=cdk_build_project, input=cdk_source_output, outputs=[cdk_build_output] ) # build your Lambda code, using CodeBuild # again, this example assumes your Lambda is written in TypeScript/JavaScript - # make sure to adjust the build environment and/or commands if they don't match your specific situation lambda_build_project = codebuild.Project(pipeline_stack, "LambdaBuildProject", environment=codebuild.BuildEnvironment( build_image=codebuild.LinuxBuildImage.STANDARD_7_0 ), build_spec=codebuild.BuildSpec.from_object({ "version": "0.2", "phases": { "install": { "commands": "npm install" }, "build": { "commands": "npm run build" } }, "artifacts": { "files": ["index.js", "node_modules/**/*" ] } }) ) lambda_build_output = codepipeline.Artifact() lambda_build_action = codepipeline_actions.CodeBuildAction( action_name="Lambda_Build", project=lambda_build_project, input=lambda_source_output, outputs=[lambda_build_output] ) pipeline.add_stage( stage_name="Build", actions=[cdk_build_action, lambda_build_action] ) # finally, deploy your Lambda Stack pipeline.add_stage( stage_name="Deploy", actions=[ codepipeline_actions.CloudFormationCreateUpdateStackAction( action_name="Lambda_CFN_Deploy", template_path=cdk_build_output.at_path("LambdaStack.template.yaml"), stack_name="LambdaStackDeployedName", admin_permissions=True, parameter_overrides=lambda_code.assign(lambda_build_output.s3_location), extra_inputs=[lambda_build_output ] ) ] )
Attributes
- bucket_name
The name of the S3 Bucket the object is in.
- object_key
The path inside the Bucket where the object is located at.
- object_version
The S3 object version.