Skip to content

Commit f444d61

Browse files
authored
Merge branch 'main' into issue#791
2 parents d381fb8 + a66e398 commit f444d61

File tree

13 files changed

+438
-31
lines changed

13 files changed

+438
-31
lines changed

.github/workflows/build-pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
# Get the list of changed files, excluding Markdown files and deleted files
3434
- name: Get changed files
3535
id: changed-files
36-
uses: tj-actions/changed-files@27ae6b33eaed7bf87272fdeb9f1c54f9facc9d99
36+
uses: tj-actions/changed-files@9934ab3fdf63239da75d9e0fbd339c48620c72c4
3737
with:
3838
files: ${{ matrix.language }}/**
3939
files_ignore: '**/*.md'

typescript/amplify-console-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"typescript": "~5.6.3"
2020
},
2121
"dependencies": {
22-
"aws-cdk-lib": "2.185.0",
22+
"aws-cdk-lib": "2.189.1",
2323
"constructs": "^10.0.0"
2424
}
2525
}

typescript/elasticbeanstalk/elasticbeanstalk-environment/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,18 @@ cdk synth
3030
cdk bootstrap
3131
cdk deploy
3232
33-
```
33+
```
34+
35+
#### How to retrieve platform or solutionStackName?
36+
37+
- `platform`
38+
```shell
39+
aws elasticbeanstalk list-platform-versions \
40+
--query 'PlatformSummaryList[*].[PlatformArn,PlatformBranchName]' --output table
41+
```
42+
43+
- `solutionStackName`
44+
```shell
45+
aws elasticbeanstalk list-available-solution-stacks \
46+
--query 'SolutionStackDetails[*].[SolutionStackName]' --output table
47+
```
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"context": {
3-
"platform": "arn:aws:elasticbeanstalk:us-east-1::platform/Tomcat 8 with Java 8 running on 64bit Amazon Linux"
3+
"platform": "arn:aws:elasticbeanstalk:us-east-1::platform/Corretto 21 running on 64bit Amazon Linux 2023/4.5.0",
4+
"solution": "64bit Amazon Linux 2023 v6.5.0 running Node.js 20"
45
},
56
"app": "node index"
67
}

typescript/elasticbeanstalk/elasticbeanstalk-environment/index.ts

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
import * as cdk from 'aws-cdk-lib';
3-
import * as elasticbeanstalk from 'aws-cdk-lib/aws-elasticbeanstalk';
3+
import { CfnApplication, CfnEnvironment } from 'aws-cdk-lib/aws-elasticbeanstalk';
4+
import { InstanceProfile, ManagedPolicy, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
45

56

67
export class CdkStack extends cdk.Stack {
@@ -11,21 +12,57 @@ export class CdkStack extends cdk.Stack {
1112
const node = this.node;
1213

1314
const appName = 'MyApp';
14-
1515
const platform = node.tryGetContext("platform");
16+
const solution = node.tryGetContext("solution");
17+
18+
19+
// Create Role:
20+
const ebRole = new Role(this, `${appName}-eb-role` , {
21+
assumedBy: new ServicePrincipal('ec2.amazonaws.com'),
22+
roleName:`${appName}-eb-role`
23+
});
24+
25+
// some managed policies eb must have
26+
ebRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AWSElasticBeanstalkWebTier'));
27+
ebRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AWSElasticBeanstalkMulticontainerDocker'));
28+
ebRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AWSElasticBeanstalkWorkerTier'));
29+
30+
//Custom policies
31+
//access to config secrets
32+
33+
const roleARN = ebRole.roleArn;
34+
35+
// Create instance profile
36+
const instanceProfile = new InstanceProfile(this, `${appName}-instance-role`, {
37+
role: ebRole,
38+
instanceProfileName: `${appName}-instance-role`,
39+
})
1640

17-
const app = new elasticbeanstalk.CfnApplication(this, 'Application', {
41+
const app = new CfnApplication(this, `${appName}-Application`, {
1842
applicationName: appName
1943
});
2044

21-
const env = new elasticbeanstalk.CfnEnvironment(this, 'Environment', {
22-
environmentName: 'MySampleEnvironment',
23-
applicationName: app.applicationName || appName,
24-
platformArn: platform
45+
const env = new CfnEnvironment(this, `${appName}-Environment`, {
46+
environmentName: `${appName}-Environment`,
47+
applicationName: appName,
48+
solutionStackName: solution,
49+
//platformArn: platform,
50+
optionSettings: [
51+
{
52+
namespace: "aws:autoscaling:launchconfiguration",
53+
optionName: "IamInstanceProfile",
54+
value: instanceProfile.instanceProfileArn,
55+
},
56+
{
57+
namespace: "aws:elasticbeanstalk:environment",
58+
optionName: "EnvironmentType",
59+
value: "SingleInstance",
60+
},
61+
]
2562
});
2663

2764
// to ensure the application is created before the environment
28-
env.addDependsOn(app);
65+
env.addDependency(app);
2966
}
3067
}
3168

typescript/elasticbeanstalk/elasticbeanstalk-environment/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"aws-cdk": "2.1004.0"
2121
},
2222
"dependencies": {
23-
"aws-cdk-lib": "2.185.0",
23+
"aws-cdk-lib": "2.188.0",
2424
"constructs": "^10.0.0",
2525
"source-map-support": "^0.5.9"
2626
}
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
{
22
"compilerOptions": {
3-
"target":"ES2018",
4-
"module": "commonjs",
5-
"lib": ["es2016", "es2017.object", "es2017.string"],
6-
"strict": true,
7-
"noImplicitAny": true,
8-
"strictNullChecks": true,
9-
"noImplicitThis": true,
10-
"alwaysStrict": true,
11-
"noUnusedLocals": true,
12-
"noUnusedParameters": true,
13-
"noImplicitReturns": true,
14-
"noFallthroughCasesInSwitch": false,
15-
"inlineSourceMap": true,
16-
"inlineSources": true,
17-
"experimentalDecorators": true,
18-
"strictPropertyInitialization":false
19-
}
20-
}
3+
"target": "ES2020",
4+
"module": "commonjs",
5+
"lib": ["es2020"],
6+
"declaration": true,
7+
"strict": true,
8+
"noImplicitAny": true,
9+
"strictNullChecks": true,
10+
"noImplicitThis": true,
11+
"alwaysStrict": true,
12+
"noUnusedLocals": false,
13+
"noUnusedParameters": false,
14+
"noImplicitReturns": true,
15+
"noFallthroughCasesInSwitch": false,
16+
"inlineSourceMap": true,
17+
"inlineSources": true,
18+
"experimentalDecorators": true,
19+
"strictPropertyInitialization": false,
20+
"typeRoots": ["./node_modules/@types"]
21+
},
22+
"exclude": ["node_modules", "cdk.out"]
23+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# SSM Document Association
2+
3+
<!--BEGIN STABILITY BANNER-->
4+
---
5+
6+
![Stability: Stable](https://img.shields.io/badge/stability-Stable-success.svg?style=for-the-badge)
7+
8+
> **This is a stable example. It should successfully build out of the box**
9+
>
10+
> This example is built on Construct Libraries marked "Stable" and does not have any infrastructure prerequisites to build.
11+
---
12+
<!--END STABILITY BANNER-->
13+
14+
## Overview
15+
16+
An example that shows how to create an SSM document and associate it with targets that meet certain conditions — in this case, based on a tag and value. Additionally, an EC2 instance is deployed with this specific tag-value combination, so the document will be executed on that instance. The document will write the current timestamp to a file on the instance every 30 minutes.
17+
18+
## How it works
19+
20+
1. SSM Document is created with a command to write the current timestamp to a file.
21+
2. SSM Document Association is created with a target tag, parameter, and schedule.
22+
3. An EC2 instance is created with the same tag-value combination as the SSM Document Association target.
23+
4. You can connect to the EC2 instance using AWS Session Manager.
24+
5. Verify the existence of the file with the timestamp.
25+
26+
27+
## Build and Deploy
28+
29+
1. Ensure aws-cdk is installed and your AWS account/region is [bootstrapped](https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html).
30+
31+
```bash
32+
npm install -g aws-cdk
33+
cdk bootstrap
34+
```
35+
36+
2. Build and deploy.
37+
_You will need to have [Docker](https://docs.docker.com/get-docker/) installed and running._
38+
39+
```bash
40+
npm run build
41+
cdk deploy
42+
```
43+
44+
You should see some useful outputs in the terminal:
45+
46+
```bash
47+
✅ SsmDocumentAssociationStack
48+
49+
✨ Deployment time: 175.86s
50+
51+
Outputs:
52+
SsmDocumentAssociationStack.DocumentName = WriteTimeToFile
53+
SsmDocumentAssociationStack.InstanceId = <INSTANCE_ID>
54+
Stack ARN: <STACK_ARN>
55+
56+
✨ Total time: 67.29s
57+
```
58+
59+
## Try it out
60+
61+
1. Deploy the stack and connect to the EC2 instance using AWS Session Manager.
62+
63+
2. Verify the existence of the file with the timestamp.
64+
65+
```bash
66+
$ ls /opt/aws/time_records/
67+
time_20250414_195134.txt
68+
$ cat /opt/aws/time_records/time_20250414_195134.txt
69+
Mon Apr 14 19:51:34 UTC 2025
70+
```
71+
72+
3. Try again, 30 minutes later, and see the new file created.
73+
74+
```bash
75+
$ ls /opt/aws/time_records/
76+
time_20250414_195134.txt time_20250414_201930.txt
77+
$ cat /opt/aws/time_records/time_20250414_201930.txt
78+
Mon Apr 14 20:19:30 UTC 2025
79+
```
80+
81+
82+
## Useful commands
83+
84+
* `npm run build` compile typescript to js
85+
* `npm run watch` watch for changes and compile
86+
* `npm run test` perform the jest unit tests
87+
* `cdk deploy` deploy this stack to your default AWS account/region
88+
* `cdk diff` compare deployed stack with current state
89+
* `cdk synth` emits the synthesized CloudFormation template
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
import * as cdk from 'aws-cdk-lib';
3+
import { SsmDocumentAssociationStack } from '../lib/ssm-document-association-stack';
4+
5+
const app = new cdk.App();
6+
new SsmDocumentAssociationStack(app, 'SsmDocumentAssociationStack');
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts bin/ssm-document-association.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21+
"@aws-cdk/core:checkSecretUsage": true,
22+
"@aws-cdk/core:target-partitions": [
23+
"aws",
24+
"aws-cn"
25+
],
26+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29+
"@aws-cdk/aws-iam:minimizePolicies": true,
30+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35+
"@aws-cdk/core:enablePartitionLiterals": true,
36+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
38+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
39+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
40+
"@aws-cdk/aws-route53-patters:useCertificate": true,
41+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
42+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
43+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
44+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
45+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
46+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
47+
"@aws-cdk/aws-redshift:columnId": true,
48+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
49+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
50+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
51+
"@aws-cdk/aws-kms:aliasNameRef": true,
52+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
53+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
54+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
55+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
56+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
57+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
58+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
59+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
60+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
61+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
62+
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
63+
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
64+
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
65+
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
66+
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
67+
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
68+
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
69+
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false,
70+
"@aws-cdk/aws-s3:keepNotificationInImportedBucket": false,
71+
"@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature": false,
72+
"@aws-cdk/aws-ecs:disableEcsImdsBlocking": true,
73+
"@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": true,
74+
"@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": true,
75+
"@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": true,
76+
"@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": true,
77+
"@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": true,
78+
"@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": true,
79+
"@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true,
80+
"@aws-cdk/aws-stepfunctions-tasks:fixRunEcsTaskPolicy": true,
81+
"@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": true,
82+
"@aws-cdk/aws-route53-targets:userPoolDomainNameMethodWithoutCustomResource": true,
83+
"@aws-cdk/aws-elasticloadbalancingV2:albDualstackWithoutPublicIpv4SecurityGroupRulesDefault": true,
84+
"@aws-cdk/aws-iam:oidcRejectUnauthorizedConnections": true,
85+
"@aws-cdk/core:enableAdditionalMetadataCollection": true,
86+
"@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy": true,
87+
"@aws-cdk/aws-s3:setUniqueReplicationRoleName": true,
88+
"@aws-cdk/aws-events:requireEventBusPolicySid": true
89+
}
90+
}

0 commit comments

Comments
 (0)