Skip to content

Instantly share code, notes, and snippets.

@pulumipus
Last active February 14, 2021 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pulumipus/304782eede89637b17b191b71b5427ae to your computer and use it in GitHub Desktop.
Save pulumipus/304782eede89637b17b191b71b5427ae to your computer and use it in GitHub Desktop.
Class to create an AWS container Lambda
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
import * as pulumi from "@pulumi/pulumi";
import * as docker from "@pulumi/docker";
const opts = { };
export class ContainerFunction extends pulumi.ComponentResource {
public CreateAwsResources(name: string, image: awsx.ecr.RepositoryImage) {
const role = new aws.iam.Role(name, {
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({
Service: "lambda.amazonaws.com"
})
}, opts);
const lambdaFullAccessCopyAttachment = new aws.iam.RolePolicyAttachment(`{name}-lambdaFullAccessCopyAttachment`, {
role: role,
policyArn: aws.iam.ManagedPolicy.AWSLambdaExecute,
}, opts)
const ecsFullAccess = new aws.iam.RolePolicyAttachment("ecsFullAccess", {
role: role.name,
policyArn: aws.iam.ManagedPolicy.AmazonECSFullAccess,
}, opts);
const func = new aws.lambda.Function(`${name}-function`, {
role: role.arn,
imageUri: image.imageValue,
packageType: "Image"
}, opts);
}
constructor(name: string, local: boolean, opts?: pulumi.ComponentResourceOptions) {
super("myapp:index:ContainerImage", name, {}, opts)
if (local) {
const image = new docker.Image(name, {
imageName: `${name}-container`,
build: {
context: "./app",
},
skipPush: true,
});
const localContainer = new docker.Container(`${name}-container`, {
image: image.imageName,
ports: [{
internal: 8080,
external: 8000,
}],
}, opts)
} else {
// this.CreateAwsResources(name, image);
const image = awsx.ecr.buildAndPushImage(name, {
context: "./app",
}, {}, opts);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment