Comments (5)
Hey @Schwar999, thanks for raising the issue.
To help us reproduce the issue, can you please share your Lambda Function Construct in CDK and corresponding Lambda Function Resource in synth-ed template?
from aws-sam-cli.
@hawflau
Thank you for your reply.
Here are some of my codes.
Would you be able to analyze them?
Synth-ed template
"func0915CAEC": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Architectures": [
"x86_64"
],
"Code": {
"S3Bucket": "cdk-xxxx",
"S3Key": "xxxx.zip"
},
"Environment": {
"Variables": {
"ENV_NAME": "dev",
"LOG_LEVEL": "debug",
"AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1"
}
},
"Handler": "index.handler",
"Layers": [
"arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:78"
],
"MemorySize": 256,
"Role": {
"Fn::GetAtt": [
"funcServiceRoleDA6E3B24",
"Arn"
]
},
"Runtime": "nodejs18.x",
"VpcConfig": {
"SecurityGroupIds": [
{
"Fn::GetAtt": [
"funcSecurityGroup8BD4105F",
"GroupId"
]
}
],
"SubnetIds": [
"subnet-000",
"subnet-001"
]
}
},
"DependsOn": [
"funcServiceRoleDefaultPolicy2124A06A",
"funcServiceRoleDA6E3B24"
],
"Metadata": {
"aws:cdk:path": "test-stack/func/Resource",
"aws:asset:path": "asset.71bec7b1e16c2b00a998c4abec8abb8ebcf9242a7b",
"aws:asset:is-bundled": true,
"aws:asset:property": "Code"
}
}
stack.ts
import { Duration, Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import { Topic } from "aws-cdk-lib/aws-sns";
import { SqsSubscription } from "aws-cdk-lib/aws-sns-subscriptions";
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
import { Architecture, LambdaInsightsVersion, Runtime, Tracing } from "aws-cdk-lib/aws-lambda";
import { Config } from "./config";
import { SubnetType, Vpc } from "aws-cdk-lib/aws-ec2";
import { Queue, QueuePolicy } from "aws-cdk-lib/aws-sqs";
import { SqsEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
import { RetentionDays } from "aws-cdk-lib/aws-logs";
import { Effect, PolicyStatement, ServicePrincipal } from "aws-cdk-lib/aws-iam";
import { QueueProps } from "aws-cdk-lib/aws-sqs/lib/queue";
export class TestStack extends Stack {
constructor(scope: Construct, id: string, props: TestStackProps, config: Config) {
super(scope, id, props);
const vpc = Vpc.fromLookup(this, "test-vpc", { vpcId: config.testVpcId });
const funcLambda = new NodejsFunction(this, `func`, {
memorySize: 256,
vpc: vpc,
vpcSubnets: vpc.selectSubnets({ subnetType: config.testVpcSubnetType as SubnetType }),
allowPublicSubnet: config.testVpcSubnetType === "Public",
runtime: Runtime.NODEJS_18_X,
timeout: Duration.seconds(config.pushNotifier.func.lambdaAndQueueVisibilityTimeoutSeconds),
environment: {
ENV_NAME: config.env,
LOG_LEVEL: config.logLevel,
},
architecture: Architecture.X86_64,
insightsVersion: LambdaInsightsVersion.fromInsightVersionArn(config.lambdaInsightsArn),
logRetention: RetentionDays.ONE_YEAR,
tracing: Tracing.ACTIVE,
});
lambda.ts
import { Context, SQSEvent, SQSRecord } from "aws-lambda";
import got from "got";
import { defaultLogger, getLogger } from "./logger";
import { captureLambdaHandler, Tracer } from "@aws-lambda-powertools/tracer";
import middy from "@middy/core";
let logger = defaultLogger;
export const handler = middy(async (event: SQSEvent, context: Context) => {
logger = getLogger(context);
const sqsRecord: SQSRecord = event.Records[0];
const sqsBody: TestMessage = JSON.parse(sqsRecord.body);
return notifySingle(sqsRecord.messageId, sqsBody.endpoint, sqsBody.payload);
}).use(captureLambdaHandler(tracer));
from aws-sam-cli.
I've tried to reproduce this issue however I was able to invoke the function locally.
Here is the folder structure;
.
├── README.md
├── bin
│ └── cdk-local.ts
├── cdk.json
├── jest.config.js
├── lib
│ ├── cdk-local-stack.func.ts
│ └── cdk-local-stack.ts
├── package-lock.json
├── package.json
└── tsconfig.json
Here are the contents of the files;
bin/cdk-local.ts
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { CdkLocalStack } from '../lib/cdk-local-stack';
const app = new cdk.App();
new CdkLocalStack(app, 'CdkLocalStack', {});
lib/cdk-local-stack.ts
export interface Response {
result: number;
}
export const handler = async (event: {}): Promise<Response> => {
const result = {
result: 10,
};
return result;
};
lib/cdk-local-stack.func.ts
import * as cdk from 'aws-cdk-lib';
import { Architecture, Runtime, Tracing } from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
import { Construct } from 'constructs';
export class CdkLocalStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// The code that defines your stack goes here
const funcLambda = new NodejsFunction(this, `func`, {
memorySize: 256,
runtime: Runtime.NODEJS_18_X,
architecture: Architecture.X86_64,
logRetention: RetentionDays.ONE_YEAR,
tracing: Tracing.ACTIVE,
});
}
}
I've used your tsconfig.json
file. I am running cdk synth
and then sam local invoke --template cdk.out/CdkLocalStack.template.json func
and I can invoke function locally.
Can you provide a reproducible example?
from aws-sam-cli.
Closing the issue, please reopen or create a new issue if you encounter any other problems.
from aws-sam-cli.
⚠️ COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
from aws-sam-cli.
Related Issues (20)
- Bug: AWS::Serverless::Function ImageUri with function (ex: using !If) fails with type error HOT 3
- Bug: Template not rendered correctly HOT 4
- Why does aws-sam-cli not support debug mode on os runtime (provided.al2 / provided.al2023)? HOT 4
- Bug: sam local start-api fails to initialise lambda function containers within podman/toolbox container HOT 4
- Feature request: support Finch HOT 2
- Bug: sam local invoke - SSLError HOT 2
- start-api debug port failure HOT 1
- start-api debug port fails HOT 5
- Bug: `sam local invoke` takes client environment variable value over defined value in template.yaml HOT 3
- Sam build with project references in adjacent directory (.NET8 NativeAOT) HOT 4
- `sam sync` with typescript not updating Lambda layer code in Lambda function HOT 4
- Bug: Docker 4.33 + Provided.al2 Image error HOT 9
- Bug: SAM Deployment Issue: Bootstrap File Not Found Despite Successful Build and Upload HOT 1
- Bug: sam pipeline init - ResourceNotFoundException HOT 1
- Bug: Official example for CDK is not working HOT 1
- Bug: Runtime.ImportModuleError for Typescript Lambda function defined using CDK HOT 2
- Feature request: Run Node tests as part of sam build HOT 1
- Bug: sam build --container-env-var is not working HOT 1
- Thumbprint of the AWS SAM Windows MSI installer does not match the documentation HOT 1
- Bug: ResourceDetailedStatus never returns as part of a cloudformation event
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sam-cli.