Skip to content

Instantly share code, notes, and snippets.

@kenfdev
Last active November 24, 2021 07:03
Show Gist options
  • Select an option

  • Save kenfdev/d801e8f999860aa4e1ea8f3a0b7b010a to your computer and use it in GitHub Desktop.

Select an option

Save kenfdev/d801e8f999860aa4e1ea8f3a0b7b010a to your computer and use it in GitHub Desktop.
CDK

Creating a CDK environment on Windows WSL

  • be sure to set .wsconfig for memory consuming issue

  • install nvm

  • install Node.js

  • install CDK CLI

  • install dotnet SDK(this takes a long time)

  • locally build a dotnet6 lambda container image (no official image atm)

  • create Lambda

    • docker build -f LambdaRuntimeDockerfiles/Images/net6/amd64/Dockerfile -t dotnet6-runtime:base-image-amd64 .
    • edit the Dockerfile as suggested by the README.md
      FROM dotnet6-runtime:base-image-amd64 AS base
      
      FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
      WORKDIR /src
      COPY ["ImportFunction.csproj", "ImportFunction/"]
      RUN dotnet restore "ImportFunction/ImportFunction.csproj"
      
      WORKDIR "/src/ImportFunction"
      COPY . .
      RUN dotnet build "ImportFunction.csproj" --configuration Release --output /app/build
      
      FROM build AS publish
      RUN dotnet publish "ImportFunction.csproj" \
                  --configuration Release \ 
                  --runtime linux-x64 \
                  --self-contained false \ 
                  --output /app/publish \
                  -p:PublishReadyToRun=true  
      
      FROM base AS final
      WORKDIR /var/task
      COPY --from=publish /app/publish .
      
      CMD ["ImportFunction::ImportFunction.Function::FunctionHandler"]
  • where's the current directory when using ImageFromAsset?

    • probably where cdk.json is
  • how to set the entrypoint for the docker image for lambda

    • set the CMD to the full qualified function path as suggested here
  • output of Lambda is inside Payload

import * as ecr from '@aws-cdk/aws-ecr';
import { TagMutability } from '@aws-cdk/aws-ecr';
new ecr.CfnRepository(this, 'BackendRepository', {
repositoryName: 'sbcntr-backend',
imageTagMutability: TagMutability.MUTABLE,
imageScanningConfiguration: {
scanOnPush: false,
},
encryptionConfiguration: {
encryptionType: 'KMS',
},
});
// any principal
new iam.PolicyStatement({
actions: ['*'],
effect: iam.Effect.ALLOW,
resources: ['*'],
principals: [new iam.AnyPrincipal()],
});
// Interface VPC Endpoint
const vpceEcrApi = new ec2.InterfaceVpcEndpoint(this, 'VpceEcrApi', {
vpc: props.vpc,
service: ec2.InterfaceVpcEndpointAwsService.ECR,
privateDnsEnabled: true,
subnets: {
subnets: props.egressSubnets,
},
securityGroups: [props.egressSecurityGroup],
});
Tags.of(vpceEcrApi).add('Name', 'sbcntr-vpce-ecr-api');
vpceEcrApi.addToPolicy(
new iam.PolicyStatement({
actions: ['*'],
effect: iam.Effect.ALLOW,
resources: ['*'],
principals: [new iam.AnyPrincipal()],
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment