Interface ILocation
An interface that represents the location of a specific object in an S3 Bucket.
Namespace: Amazon.CDK.AWS.S3
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public interface ILocation
Syntax (vb)
Public Interface ILocation
Remarks
ExampleMetadata: lit=aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts infused
Examples
var lambdaStack = new Stack(app, "LambdaStack");
var lambdaCode = Code.FromCfnParameters();
new Function(lambdaStack, "Lambda", new FunctionProps {
Code = lambdaCode,
Handler = "index.handler",
Runtime = Runtime.NODEJS_LATEST
});
// other resources that your Lambda needs, added to the lambdaStack...
var pipelineStack = new Stack(app, "PipelineStack");
var pipeline = new Pipeline(pipelineStack, "Pipeline", new PipelineProps {
CrossAccountKeys = true
});
// add the source code repository containing this code to your Pipeline,
// and the source code of the Lambda Function, if they're separate
var cdkSourceOutput = new Artifact();
var cdkSourceAction = new CodeCommitSourceAction(new CodeCommitSourceActionProps {
Repository = new Repository(pipelineStack, "CdkCodeRepo", new RepositoryProps {
RepositoryName = "CdkCodeRepo"
}),
ActionName = "CdkCode_Source",
Output = cdkSourceOutput
});
var lambdaSourceOutput = new Artifact();
var lambdaSourceAction = new CodeCommitSourceAction(new CodeCommitSourceActionProps {
Repository = new Repository(pipelineStack, "LambdaCodeRepo", new RepositoryProps {
RepositoryName = "LambdaCodeRepo"
}),
ActionName = "LambdaCode_Source",
Output = lambdaSourceOutput
});
pipeline.AddStage(new StageOptions {
StageName = "Source",
Actions = new [] { cdkSourceAction, lambdaSourceAction }
});
// 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
var cdkBuildProject = new Project(pipelineStack, "CdkBuildProject", new ProjectProps {
Environment = new BuildEnvironment {
BuildImage = LinuxBuildImage.STANDARD_7_0
},
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string>> {
{ "install", new Struct {
Commands = "npm install"
} },
{ "build", new Struct {
Commands = new [] { "npm run build", "npm run cdk synth LambdaStack -- -o ." }
} }
} },
{ "artifacts", new Dictionary<string, string> {
{ "files", "LambdaStack.template.yaml" }
} }
})
});
var cdkBuildOutput = new Artifact();
var cdkBuildAction = new CodeBuildAction(new CodeBuildActionProps {
ActionName = "CDK_Build",
Project = cdkBuildProject,
Input = cdkSourceOutput,
Outputs = new [] { cdkBuildOutput }
});
// 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
var lambdaBuildProject = new Project(pipelineStack, "LambdaBuildProject", new ProjectProps {
Environment = new BuildEnvironment {
BuildImage = LinuxBuildImage.STANDARD_7_0
},
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string>> {
{ "install", new Struct {
Commands = "npm install"
} },
{ "build", new Struct {
Commands = "npm run build"
} }
} },
{ "artifacts", new Dictionary<string, string[]> {
{ "files", new [] { "index.js", "node_modules/**/*" } }
} }
})
});
var lambdaBuildOutput = new Artifact();
var lambdaBuildAction = new CodeBuildAction(new CodeBuildActionProps {
ActionName = "Lambda_Build",
Project = lambdaBuildProject,
Input = lambdaSourceOutput,
Outputs = new [] { lambdaBuildOutput }
});
pipeline.AddStage(new StageOptions {
StageName = "Build",
Actions = new [] { cdkBuildAction, lambdaBuildAction }
});
// finally, deploy your Lambda Stack
pipeline.AddStage(new StageOptions {
StageName = "Deploy",
Actions = new [] {
new CloudFormationCreateUpdateStackAction(new CloudFormationCreateUpdateStackActionProps {
ActionName = "Lambda_CFN_Deploy",
TemplatePath = cdkBuildOutput.AtPath("LambdaStack.template.yaml"),
StackName = "LambdaStackDeployedName",
AdminPermissions = true,
ParameterOverrides = lambdaCode.Assign(lambdaBuildOutput.S3Location),
ExtraInputs = new [] { lambdaBuildOutput }
}) }
});
Synopsis
Properties
BucketName | The name of the S3 Bucket the object is in. |
ObjectKey | The path inside the Bucket where the object is located at. |
ObjectVersion | The S3 object version. |
Properties
BucketName
The name of the S3 Bucket the object is in.
string BucketName { get; }
Property Value
System.String
ObjectKey
The path inside the Bucket where the object is located at.
string ObjectKey { get; }
Property Value
System.String
ObjectVersion
The S3 object version.
virtual string ObjectVersion { get; }
Property Value
System.String